As of version 3.0 tabulator renders its table using a Virtual DOM, this means that it only renders the rows you seen in the table (plus a few above and below the current view) and creates and destroys the rows as you scroll through the table.
The table below has 1000 rows loaded as they are needed as you scroll
By setting the fitColumns option 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.
By setting the responsiveLayout option to true, the table will automatically hide/show columns to prevent the columns from exceeding the width of container.
If you resize the the width of the window you will see the number of columns change to ensure the data fits with the table. This option can be combined with fitColumns to make a table that gracefully responds to all display widths.
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
color - sets the background color of the cell to the value. Can be any valid css colour eg. #ff0000, #f00, rgb(255,0,0), red, rgba(255,0,0,0), hsl(0, 100%, 50%)
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
buttonTick - displays a tick icon on eac row (for use as a button)
buttonCross - displays a cross icon on eac row (for use as a button)
rownum - shows an incrementing row number for each row.
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.
You can also set a row formatter using the rowFormatter option, this allows you to format the styling of the row as a whole
If you are looking for a non grid based format to your table then you can use a row formatter to create custom row layouts.
You can use the rowFormatter callback to replace the contents of the row with any layout you like. In this example we will create a simple table in each row containg and image and some vertically centered text properties.
When replacing the entier contents of the row it is important to include only one column in your column definition array to ensure the table renders correctly. It is also advisable to enable fitColumns and disabled resizableColumns options.
We will be passing an array of values into a field and then using a custom formatter to turn this array into a sparkline.
The Sparklines library can be downloaded from Git Hub.
Column calculations can be useed to add a row of calcualted values to the top or bottom of your table to display infmation such as the sum of a columns data.
There are two options that can be set in a column definition object to define a calculation, the topCalc option defines a calculation for the top of the column, and the bottomCalc defines a calculation for the bottom of the column. You can define, either, both or neither of the options.
It is possible to convert a standard HTML Table element into a tabulator, pulling all the data directly from the table into the tabulator when it is created.
If you want to pull the column headers in from the table, you need to make sure that you have defiend a thead element with each column header in a th element. If you specify the width attribute on a header, then this will be set as the width of the column in the tabulator.
You can set any of the standard Tabulator options when you create your table this way, so can easily convert old tables to take advantage of the many features Tabulator has to offer.
By default Tabulator will attempt to guess which sorter should be applied to a column based on the data contained in the first row. It can determine sorters for strings, numbers, alphanumeric squences and booleans, anything else will be treated as a string.
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
time - sorts column as times
To specify a sorter to be used on a column use the param property in the columns definition object
You can define a custom sorter functions in the sorter option if you need bespoke sorting functionality.
You can programmatically trigger a sort using the sort function.
Tabulator allows you to paginate your data. simply set the pagination property to true.
If you have set the height of the table then the data will be automatically paginated to fit within the table.
If you wish to define how many rows should be shown on a page, set this in the paginationSize property. If you set the paginationSize without setting the height, the Tabulator will automatically resize to fit the data
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 cellClick 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 is styled using a full set of CSS classes, making theming of the table very simple. A full list of these can be found here.
A LESS file is also provided, containing a set of variables to make generating your own theme even easier. This can be found in tabulator.less
Tabulator comes with a number of packaged themes in the /dist/css/ directory of the package. To use one of these simply include the matching css file instead of the default tabulator.css
The standard generic table theme. This can be found in /dist/css/tabulator.min.css
A plain, simplistic layout showing only basic grid lines. This can be found in /dist/css/tabulator_simple.min.css
A dark, stylish layout using simple shades of grey. This can be found in /dist/css/tabulator_midnight.min.css
A neat, stylish layout using one primary color. This color can be set in the @primary variable in the /dist/css/tabulator_modern.less file to alter the style to match your colour scheme. This can be found in /dist/css/tabulator_modern.min.css
Match Tabulator to the standard Bootstrap theme /dist/css/bootstrap/tabulator_bootstrap.min.css
Semantic UI Theme
Match Tabulator to the standard Semantic UI theme /dist/css/semantic-ui/tabulator_semantic-ui.min.css
Manually Adjusted Theme
You can override the defualt tabulator styling in document, or simply edit the provided tabulator.min.css file to make your own custom theme.