Tabulator-基于jQuery UI的实用表格插件 A table generation JQuery UI Plugin
An easy to use table generation JQuery UI Plugin
Tabulator allows you to create a table with in seconds from any JSON formatted data.
It relies on no external css or images, simply include the library in your JQuery UI project and you're away!
Tabulator is packed with useful features including:
- JSON, array or AJAX data loading
- Column sorting
- Custom data formatting
- Resizable columns
- Auto scaling to fit data/element
- Many theming options
- Custom click and context Events
- Callbacks at every stage of data processing and rendering
In its simplest form, all you need to set in the options are the column titles and field names.
By default columns are resizable (using edge of column header) and sortable (as strings).
Tables will automatically resize to fit the data
By setting the fitColumns to true, the table will resize columns so that they fit perfectly inside the width of the container.
If a width is specified on any columns, where possible the columns will be set at this width and other columns will be resized around them. If there is not enough space to fit all the columns in, then all column widths are ignored and they are sized equally.
Using the editable setting on each column, you can make a user editable table.
Any time a cell is edited it triggers the rowEdit callback, to allow you to process any changes.
You can call the getData method to get an array of all of the tables data, including any edits
Sorting is enabled by default, and can be toggled on or off by column using the sortable option.
By default all columns are sorted as text, different sort functions can be set using the sorter option
- string - sorts column as strings of characters
- number - sorts column as numbers (integer or float, will also handle numbers using "," seperators)
- alphanum - sorts column as alpha numeric code
- boolean - sorts column as booleans
- date - sorts column as dates (for this you will need to set the date format using the dateFormat option when you create your table. default format is "dd/mm/yyyy")
You can define a custom sorter functions in the sorter option if you need bespoke sorting functionality.
Tabulator allows you to format your data in a wide variety of ways, so your tables can display information in a more graphical and clear layout.
you can set formatters on a per column basis using the formatter option in the column data.
Tabulator comes with a number of preconfigured formatters including:
- money - formats a number into a currency notation (eg. 1234567.8901 -> 1,234,567.89)
- email - renders data as an anchor with a mailto: link to the given value
- link - renders data as an anchor with a link to the given value
- tick - displays a green tick if the value is (true|'true'|'True'|1) and an empty cell if not
- tickCross - displays a green tick if the value is (true|'true'|'True'|1) and a red cross if not
- star - displays a graphical 0-5 star rating based on integer values from 0-5
- progress - displays a progress bar that fills the cell from left to right, using values 0-100 as a percentage of width
You can define a custom formatter function in the formatter option if you need more bespoke formatter functionality
You can create icon/button columns, by not specifying a field parameter in the column data and creating a custom formatter for the column contents. In the example below we have created a print button on the left of each row.
Tabulator allows you to filter the table data by any field in the data set.
To set a filter you need to call the setFilter method, passing the field you wish to filter, the comparison type and the value to filter for
Tabulator comes with a number of filter comparison types including:
- = - Displays only rows with data that is the same as the filter
- < - displays rows with a value less than the filter value
- <= - displays rows with a value less than or qual to the filter value
- > - displays rows with a value greater than the filter value
- >= - displays rows with a value greater than or qual to the filter value
- != - displays rows with a value that is not equal to the filter value
- like - displays any rows with data that contains the specified string anywhere in the specified field. (case insesitive)
Data can be loaded into the table from a remote URL using a JSON formatted string.
If you always request the same URL for your data then you can set it in the ajaxURL option when you create your Tabulator
Click the button below to load sample data via AJAX (you will need PHP enabled on your webserver for this to work).
Tablulator allows you to add new rows, delete existing rows and cleat all table data with ease.
Tabulator features a range of callbacks to allow you to handle user interaction.
- Cell Click - The cell click callback is triggered when a user left clicks on a cell, it can be set on a per column basis using the onClick option in the columns data. (left click any cell in the gender column in this example)
- Row Click - The row click callback is triggered when a user clicks on a row, it can be set globally, by setting therowClickoption when you create your Tabulator. (left click any row in this example)
- Row Context Menu - The row context callback is triggered when a user right clicks on a row, it can be set globally, by setting the rowContext option when you create your Tabulator. (right click any row in this example)
- Data Loaded - The data loaded callback is triggered when a new set of data is loaded into the table, it can be set globally, by setting the dataLoaded option when you create your
Tabulator has a range of additional options to help customise your table. A full list of these can be found in the GitHub readme.md file