Tabulator tables
KVision Tabulator component is based on awesome Tabulator library. It allows you to create interactive and reactive tables, with advanced sorting, filtering and editing capabilities. Tabulator component can be integrated with ObservableList<T> or Redux store and will automatically react to all changes in your data model. This component is contained in kvision-tabulator module. KVision adds Kotlin type-safe bindings for most of Tabulator API but you should get familiar with Tabulator documentation to achieve best results.
Note: At the moment these functionalities are not supported: grouping, mutators, column calculations, download. Please fill a feature request if you require any of these.
Creating a table
To create a table use pl.treksoft.kvision.tabulator.Tabulator
class. Although all constructor parameters have default values, you will usually want to specify Tabulator options with pl.treksoft.kvision.tabulator.TabulatorOptions
object . The table data can be specified in a few different ways - with local Kotlin collection, local JavaScript array or remote AJAX URL. The table component can be made reactive for all types of local data.
Local Kotlin list
Data classes are preferred objects representing a single row data.
To make the Tabulator component reactive just can use ObservableList
for your model. You can also use Redux store as a table data source.
Local JavaScript array
You should use Any
as your Tabulator type parameter and leave both data
and dataSerializer
constructor parameters with null
values. You pass a reference to native JS array with a data
parameter inside your TabulatorOptions
object.
To make the Tabulator component reactive use reactiveData = true
parameter inside your TabulatorOptions
object.
Remote AJAX URL
Tabulator tables can get the data from the remote endpoint. You can find more information about available options in the Tabulator documentation. All these options, including ajax sorting, pagination and filtering can be used with KVision component.
Formatting the data
Built-in formatters
You can use many different formatters to present the data in the tabulator cells. Just pass the desired Formatter
as a formatter
parameter in ColumnDefinition
.
Tabulator currently supports the following built-in formatter types: Formatter.PLAINTEXT
, Formatter.TEXTAREA
, Formatter.HTML
, Formatter.MONEY
, Formatter.IMAGE
, Formatter.LINK
, Formatter.DATETIME
, Formatter.DATATIMEDIFF
, Formatter.TICKCROSS
, Formatter.COLOR
, Formatter.STAR
, Formatter.TRAFFIC
, Formatter.PROGRESS
, Formatter.LOOKUP
, Formatter.BUTTONTICK
, Formatter.BUTTONCROSS
, Formatter.ROWNUM
, Formatter.HANDLE
. You can find more information about formatters configuration in the Tabulator docs.
Note: You need to include kvision-moment
module to use built-in date/time formatters.
Custom formatters
You can use any KVision components to display data in Tabulator cells. You define the component with the formatterComponentFunction
property of the ColumnDefinition
class. When the Tabulator component is bound to the Kotlin data source, this function gives you also direct and type-safe access to the Kotlin data model for the current row.
Local filtering
Tabulator component allows you to filter the data with external, fully type-safe Kotlin code. You can set the filtering function with setFilter
method, and then use applyFilter
after the condition change (e.g. after search input value change).
Editing the table
Built-in editors
Tabulator also allows you to edit the values in each cell according to a user specified Editor
type. Just pass the desired Editor
as an editor
parameter in ColumnDefinition
.
Tabulator currently supports the following built-in editor types: Editor.INPUT
, Editor.TEXTAREA
, Editor.NUMBER
, Editor.RANGE
, Editor.TICK
, Editor.STAR
, Editor.SELECT
and Editor.AUTOCOMPLETE
Custom editors
You can use most of KVision components to edit data in Tabulator cells. You define the component with the editorComponentFunction
property of the ColumnDefinition
class. When the Tabulator component is bound to the Kotlin data source, this function gives you also direct and type-safe access to the Kotlin data model for the current row.
Note: Not all KVision edit controls work well inside Tabulator cells. Currently you cannot use Select
component, because of conflict in event handling. You can use SimpleSelect
without problems, though.
Automatic model update
When using editable table with Tabulator component bound to Kotlin MutableList
data model, the changed data is automatically updated in the model. You can disable this function by setting dataUpdateOnEdit
Tabulator constructor parameter to false
.
Last updated