This is currently still in production.
import DataTableWrapper from 'DataTableWrapper.jsx';
let MyTable = DataTableWrapper("someUniqueName");
...js
<MyTable ... />
...
DataTableWrapper
is higher order component(HOC) that will return a component, in this case "MyTable". Therefore, you can then use <MyTable />
in your component and pass whatever props you need (see below). You can create as many datatables as you need and they will behave independently of each other.
Simply add a dataTables
Object to the root of your store, e.g. dataTables: {}
. This object contains the following properties:
-
loading (Boolean): Indicates if the table data is in the process of being loaded.
-
sortingEnabled (Boolean): Indicates if column sorting is enabled on the table.
-
queryParams (Object): Contains properties used by the
dataFetchFunction
function. Namely:- searchParams (Object)
- sortParam: (Object)
- skip: (Integer)
- limit: (Integer)
-
searchParamsDict (Object):
-
searchTerm (String):
-
pageSizeList (Array): An array of values that the user of the datatable can select to adjust the page size. Default is
[50,200,500]
. -
dataFetchTriggerKey (String): Changing the value of this key will force a re-fetch of the data in the table.
-
data (Array): An array of objects representing the data to be insterted into the table.
columnConfig
(Array of Objects)
Provides information about the data stored in each column. Each column is represented by an Object with the following properties:
- className (String): The CSS class name to apply to each table cell of this column.
- content (String): The content of the column header cell.
- dbField (String): The name of the field (in the database) that the column matches to.
- dbSearchField (String): If a search field is used with the table to filter the data, this refers to the name of the field (in the database) that the search facility will use.
- sorting (Boolean): Enable/disable sorting on the table column.
- style (Object): Inline CSS styles to be applied to each cell of this column.
defaultColumnSorting
(Object)
Provides information about how the table should be sorted when it is initially rendered.
- index (Interger): A zero-based index of the column number.
- field (String): The field (in the database) that represents the data in the column.
- dir (String): The direction of the sort (either 'asc' or 'desc').
dataFetchFunction
(Function)
A function that will fetch data to pass to the Data Table. It receives the queryParams
object as its first argument. This function must return a Promise.
renderRow
(Function)
A function that will process each row of data returned by the dataFetchFunction
. The renderRow
function will be supplied with an Object that will represent the row data and should return an Object:
- attr (Object): Each property within this object will be applied to the row as an attribute of the
<tr>
element. - data (Array): An array, where each element represents the content of the column within the row.
tableClass
(String)
A CSS class name that will be added to the rendered table.
Generates a unique id. Can be used to generate a value for the refetch
prop.