Skip to main content

DataTable

DataTable is a wrapper around Kyber's suite of Table components. At its most basic, the DataTable will render a standard table when provided with a set of data and columns.

Users can also use plugins with the DataTable to allow for additional features like bulk actions, filtering, rearranging columns, and more. When adding plugins to your DataTable, a toolbar will be added to the top of the table with each of the configured plugins. Examples of these plugins can be found below.

In all examples, the data and columns props provided to the DataTable must adhere to a couple rules. Your columns should be an array of objects containing a key and a label. The label is what will be displayed in the table header, and the key is a unique identifier for that column. Your data should be an array of objects containing a unique id for the entire row as well as a key/value pair representing each of the columns and the associated value for that particular row. For example, a column defined as { key: 'income', label: 'Income' } would match a row that looks like { id: 'some_id', income: 100, otherColumn: otherValue }. Check out the code snippet in each of the examples below to see what this looks like.

All of these plugins are compatible with one another so they can be used at the same time. The order they are passed into the plugins array does not matter.

NOTE: When using usePagination in conjunction with useBulkActions, selecting all rows by clicking the checkbox in the table header will only select the rows on the page that is currently visible.

Result
Loading...
Live Editor

With Custom Column

The DataTable in this example is not using any plugins. However, an optional cellRenderer was added to the "name" column to render a TextField instead of just rendering plain text.

Result
Loading...
Live Editor

Custom Plugin

Custom plugins can be created and added to the list of plugins for DataTable. They are functions that return an object that exposes the following API:

const useDownload = (props = {}) => ({
key: 'useDownload',
props,
useFilter,
Component,
});

useFilter is a function that returns the next set of data usually based on changes to the plugin.

Component is a Component that will be rendered within the header of the DataTable.

See the useDownload plugin function in the demo for implementation details.

Result
Loading...
Live Editor

Props