Coder Social home page Coder Social logo

robertoprevato / kingtable Goto Github PK

View Code? Open in Web Editor NEW
68.0 10.0 17.0 878 KB

Library for administrative tables that are able to build themselves, on the basis of the input data.

License: MIT License

Python 1.96% HTML 2.49% JavaScript 89.24% CSS 5.96% PHP 0.35%
javascript table administration admin-dashboard admin-ui es6 tables

kingtable's Introduction

KingTable

Library for administrative tables that are able to build themselves, on the basis of their input data. Supports client and server side pagination; client and server side search; custom filters views; automatic menu to hide columns and support for custom tools. Client side export feature into: csv, json, xml, Excel xlsx (using plugin) formats.

Live demo

Objectives of the library

  • Allow the implementation of administrative tables with the smallest amount of code possible.
  • Allow for easy customization of generated HTML, to adapt to different needs: e.g. displaying pictures thumbnails, anchor tags, etc.
  • Support both collections that require server side pagination, and collections that don't require server side pagination, but may still benefit from client side pagination.
  • Avoid dependencies from third party libraries, to be reusable with any other kind of library (it's plain vanilla JavaScript)

Live demo

The following demos are available online:

Note how filters are automatically persisted upon page refresh. For example, using the search feature or changing page in one of the rich HTML demos, and then hitting F5. When searching, note how client side search algorithm also sorts results by relevance (number of occurrences, order of properties that generate a match).

NB: all these demos are fixed tables: tables that have all information loaded in memory, paginated and filtered on the client side. To see examples of tables paginated using AJAX requests (on the server side), see the dedicated documentation and development server provided in the repository.

Install using npm

KingTable library can be installed using npm.

npm install kingtable

Modules can then be imported using CommonJS syntax:

var KingTable = require("kingtable")
var KingTableUtils = require("kingtable/utils")

Or ES6 import syntax:

import KingTable from "kingtable"
import KingTableUtils from "kingtable/utils"

Use downloading distribution files

KingTable library can be used downloading and using distribution files, in dist folder.

<script src="kingtable.js"></script>

Themes

Live demo - themes

Previous version

The previous version of the KingTable library is available at: https://github.com/RobertoPrevato/jQuery-KingTable.

Documentation

Refer to the wiki page. A full list of possible options is available inside the dedicated Options page.

Features of the new version

Following is a table listing the features that were added to KingTable 2.0.

Feature Description
ES6 source code ES6 source code, library is transpiled to ES5 for distribution.
Unit tested source code Source code is integrated with Gulp tasks, Karma, Jasmine for unit tests. More than 300 tests - still to grow!
Removed dependencies Removed dependency from jQuery, Lodash, I.js, R.js.
Improved exceptions Raised exceptions include a link to GitHub wiki with detailed instructions.
Improved logic to fetch data Allows to choose between HTTP GET method (filters in query string) or HTTP POST method (filters as JSON POST data).
LRU cache Least Recently Used caching mechanism to cache the last n pages by filters, to reduce number of AJAX requests.
Table data fetch logic Allows to define functions that return data required to render the table itself (e.g. dictionaries for custom filters views)
Caching of filters Filters for each table are cached using client side storage (configurable), so they are persisted upon page refresh.
Improved CS sorting Strings that can be sorted like numbers (like "25%", "25.40 EUR", "217°") are automatically parsed as numbers when sorting.
Improved CS sorting Client side sorting by multiple properties.
Improved CS search Client side search feature has been improved: search works in culture dependent string representations of dates and numbers and other formatted strings.
Improved support for event handlers Custom event handlers receive automatically the clicked item as parameter, if applicable.
Improved support for custom buttons It's now possible to configure extra fields (such as buttons) to be rendered for each item.
Improved support for other medias Support for NodeJS console applications and HTML tables rendering for email bodies sent using NodeJS.

Modes

The KingTable library implements two working modes:

  • fixed (collections that do not require server side pagination)
  • normal (collections that require server side pagination)

And supports both optimized and simple collections. Refer to the dedicated wiki page for more information.

Fixed mode

A fixed table is displaying a collection that doesn't require server side pagination, but may still benefit from client side pagination. When working on applications, it commonly happens to deal with collections that are not meant to grow over time, and they have a small size. For example, a table of categories in a e-commerce website to sell clothes, or a table of user roles in most applications. In these cases, it makes sense to return whole collections to the clients. There are two ways to define a fixed KingTable:

  • instantiating a KingTable with url from where to fetch a collection; then code the server side to return an array of items
  • instantiating a KingTable passing a data option with an instance of array: in this case, it is assumed that the collection is fixed
var table = new KingTable({
  data: [{...},{...},{...}]
});
//or... code the server side to return an array of items (instead of an object describing a paginated set of results)
var table = new KingTable({
  element:  document.getElementById("my-table"),
  url: "/api/categories"
});

Fixed tables perform search and pagination on the client side.

Normal mode

A normal table is one displaying a collection that requires server side pagination, since it is meant to grow over time. This is true in most cases, for example tables of products and customers in a e-commerce website.

var table = new KingTable({
  url: "/api/profiles"
});

When receiving an AJAX response, a normal table expects to receive the following structure:

{
  subset: [array],// array of items that respect the given filters
  total: [number] // the total count of items that respect the given filters; excluding the pagination: for example 13000
}

Usability

The KingTable library includes a number of features to improve usability, both for final user and for programmers using the library:

  • the user should be able to immediately understand the size of the collection, so the pagination bar is designed to display the total amount of rows; of pages, and the number of results currently displayed
  • all filters are automatically stored in storage (configurable sessionStorage, localStorage or compatible object) and persisted upon page refresh - filters are collected by URL and, if possible, table id
  • the above include: page number, page size, sorting criteria, text search and additional filters that can be implemented by programmer
  • data is stored for a configurable amount of milliseconds, to avoid useless AJAX calls (LRU caching mechanism)
  • support for browser navigation buttons
  • ajax errors and loading state are automatically handled

For further information, refer to the dedicated wiki page.

About localization

For full information, refer to the dedicated wiki page. The KingTable library includes logic to implement client side localization, which is used to display proper names of buttons (refresh, page number, results per page, etc.).

How to integrate with your project

Please refer to the dedicated wiki page, for instructions on how to integrate with your project and with server side code.

Dependencies

kingtable's People

Contributors

robertoprevato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kingtable's Issues

When sorting a type:"text" column, and the first row is a number eg "911", it crashes

kingtable.js:1 Uncaught TypeError: Cannot read property 'length' of null
at s (lib/kingtable/kingtable.js:1:1240)
at Object.compareStrings (lib/kingtable/kingtable.js:1:2685)
at lib/kingtable/kingtable.js:1:3498
at Array.sort (native)
at Object.sortBy (lib/kingtable/kingtable.js:1:3134)
at t.value (lib/kingtable/kingtable.js:3:20622)
at t.value (lib/kingtable/kingtable.js:3:21114)
at t.value (lib/kingtable/kingtable.js:4:13091)
at HTMLDivElement.u (lib/kingtable/kingtable.js:2:7815)

BTW i love your project so far
thank you

Large dataset issue

I have a large dataset (already filtered url eg---http://localhost/getdata.php?gender=M, and data is about 30,000+ when filtered) and i keep getting this error Uncaught (in promise) DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of '/<myfolder>/.kt:::catalogs' exceeded the quota.

I tested with smaller data set (<5000) records and it worked fine.

Am i doing something wrong?
Sorry from contacting you here. I didnt know where else to reach you*

Options menu not closing

The options (the one displayed when clicking the gear icon) only close when i click somewhere within the table. It would be great if it would close when i click anywhere within the DOM

KingTable with Firestore

Hi there,
Has anyone used this with Firestore and could send through an example please?

I am creating my own project, where I use an iPhone to record data and then display this via a web-page. Coding is a hobby of mine, something to do part time and I've only started picking up website development a couple of weeks ago.

I have been working with iOS for a while now and can competently code but am struggling for good examples of a Data Table with Firestore for website.

Can anyone help thanks?

TypeError: s.concat is not a function

Hi
I am getting the following error while using fields option as given in the example. Can you please help.
fields: {
edit: {
name: "edit-btn",
html: function (item) { return "Edit"; }
}
}
Error:
Uncaught (in promise) TypeError: s.concat is not a function
at t.value (kingtable.js:12)
at t.value (kingtable.js:14)
at t.value (kingtable.js:14)
at t.value (kingtable.js:14)
at t.value (kingtable.js:13)
at i (kingtable.js:13)
at kingtable.js:13

Custom filters?

Quick question, where are custom filters with client side filtering? I'm able to see only in the old documentation. How should I implement them with the 2.0 version?

Groupable Option

Hi,

I was wondering whether or not grouping would be developed? This plugin is perfect for what I need, but unfortunately I need grouping of rows to make it feasible. Thanks for your great work on it so far!

Kind regards,
Matt

Trying to extend KingTable.Schemas.DefaultByType (says _ is not defined)

So in a new template which I've mostly re-used the rhtml-colors.html template,
I'm giving in numbers which are percent type.
Unfortunately, I'm not very good at javascript, but I'm getting the error of
not defined "_" from console, when I added the extension script.
Could you help me understand.

<script>
  (
    function () {
      _.extend(KingTable.Schemas.DefaultByType, {
        percent: function (columnSchema, objSchema) {
          return {
            format: function (value) {
              // TODO: implement your formatting logic
              // (for thousands separator, decimal separators) - culture dependent
              return value * 100 + " %";
            }
          };
        }
      });
      var table = window.table = new KingTable({
        id: "data-table",
        url: "/api/mydata",
        caption: "KingTable - portfolio demo with server side pagination (paginated set in memory)",
        element: document.getElementById("main"),
        columns: {
          {{ instruct|safe }}
        }
      });

      table.render().then(function () {
        console.log("ok :)");
      }, function () {
        console.log("noo :(");
      });
    }
  )();

TypeError: Cannot read property 'length' of null

Hello! I caught error when used KingTable with data of following format:
All data : [Object, Object, Object, Object…]
Object: Object
CampaignID:13572830
ClicksContext:0
ClicksSearch:0
GoalConversionContext:0
GoalConversionSearch:0
GoalCostContext:0
GoalCostSearch:0
SessionDepthContext:0
SessionDepthSearch:0
ShowsContext:0
ShowsSearch:1
StatDate:"2015-10-11"
SumContext:0
SumSearch:0
proto:Object

The error:

Uncaught (in promise) TypeError: Cannot read property 'length' of null
    at s (http://localhost:3000/static/js/libs/kingtable.js:66:33)
    at Object.compareStrings (http://localhost:3000/static/js/libs/kingtable.js:131:14)
    at http://localhost:3000/static/js/libs/kingtable.js:173:33
    at Array.sort (native)
    at Object.sortBy (http://localhost:3000/static/js/libs/kingtable.js:154:14)
    at t.value (http://localhost:3000/static/js/libs/kingtable.js:4049:41)
    at t.value (http://localhost:3000/static/js/libs/kingtable.js:4023:13)
    at t.value (http://localhost:3000/static/js/libs/kingtable.js:4716:17)
    at t.value (http://localhost:3000/static/js/libs/kingtable.js:4653:31)
    at t.value (http://localhost:3000/static/js/libs/kingtable.js:4635:49)
s @ kingtable.js:66
compareStrings @ kingtable.js:131
(anonymous) @ kingtable.js:173
sortBy @ kingtable.js:154
value @ kingtable.js:4049
value @ kingtable.js:4023
value @ kingtable.js:4716
value @ kingtable.js:4653
value @ kingtable.js:4635
value @ kingtable.js:3842
i @ kingtable.js:3775
a @ kingtable.js:3779
(anonymous) @ kingtable.js:3797
value @ kingtable.js:3773
value @ kingtable.js:5086
u @ kingtable.js:2034

Can somebody help me with that?

Server.py not working, 404 code

127.0.0.1 - - [13/Jun/2019 20:01:00] " [37mGET / HTTP/1.1 " 200 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " [37mGET /styles/kingtable.css HTTP/1.1 " 200 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /rp.png HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /styles/examples.css HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /scripts/es6-promise.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:00] " GET /scripts/blob.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " [37mGET /rhtml-colors HTTP/1.1 " 200 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /styles/examples.css HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/es6-promise.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /rp.png HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/blob.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/es6-promise.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/blob.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:02] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:38] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:38] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:38] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:38] " GET /scripts/blob.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " [37mGET /colors HTTP/1.1 " 200 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /styles/examples.css HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/es6-promise.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /rp.png HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/example-controls.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/blob.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:40] " GET /scripts/example-controls.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:50] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:52] " [37mGET /colors-fixed HTTP/1.1 " 200 -
127.0.0.1 - - [13/Jun/2019 20:01:52] " GET /styles/examples.css HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:52] " GET /rp.png HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:52] " GET /scripts/es6-promise.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/kingtable.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/kingtable.xlsx.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/colors.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/example-controls.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/xlsx.core.min.js HTTP/1.1 " 404 -
127.0.0.1 - - [13/Jun/2019 20:01:53] " GET /scripts/blob.js HTTP/1.1 " 404 -

Select multiple rows

It would be nice to be able to select and take action (ie: delete) on multiple/all items at once. Maybe have the option for a select column with checkboxes for each row and a select all for the row header.

Improve the xlsx plugin

Improve the built-in xlsx plugin, so it can be imported using CommonJS and ES6 import syntax, and can be published in the npm package.

how to handle query cursor?

Hello there! We are trying to implement kingTable into our software.
However I cannot get it working as expected. I am trying to request data from the server and prepare this as JSON for kingtable to read. I have to limit my query to 99 objects and therefore need to pass a cursor to continue, and I can provide the total number of expected entries.

Is there any possibility to pass on a query cursor to kingTable?

open-iconic font not displayed

Hello there!

I recently used kingtable, its nice and neat.

But the problem is , the font u using in KingTable is not displayed after rendering. I checked at console, there is no problem like 404 to link open-iconic fonts with the project.

Please fix this issue asap...

Column's template option has no effect?

I've been trying to use the template option for a column so that a product name can link to another page, though I've been unable to get the template option to have any effect on the table.

columns: {
    _id: {
    name: "Id",
    template: "<a href='/some/url/{{_id}}'>Go to details</a>"
  },

I tried to recreate the example code (as above) directly to create a details link and that also causes no change in the table. I was just wondering if this feature's implementation is complete or if I should write my own little piece of javascript to add links within td tags?

Columns jump on column click (sort)

Is there a way to keep column widths the same, but still automatic?

Whenever I sort by column, the column header I clicked on jumps left/right

Disable Caching or reduce refresh

Hi,
I am a newbie here, and want to use this library for a project am engaged in.
Currently am working on the data on Development and the caching is getting on my nerves, as the table seem not to change as fast as am testing out the properties sent from server.
Continuously getting the error below, believe it has something to do with cached data;

image

Have set the options as below;

 storeTableData: false,
                lruCacheMaxAge: 1,
                lruCacheSize: 1

but seem to take forever or not at all to clear.

Quick assistance will be appreciated.
Thanks for the good work so far.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.