DataTable
An advanced React table that supports filtering, sorting, and pagination out of the box.
Usage
DataTable Props
| Prop | Type | Default |
|---|---|---|
columns | any[] | - |
data | T[] | - |
mode | "client" | "server" | "client" |
isLoading | boolean | false |
defaultSort | any | - |
query | DataTableQuery | - |
onTableQueryChange | ((query: DataTableQuery) => void) | - |
onLoadMore | (() => Promise<void>) | - |
DataTableQuery Interface
| Prop | Type | Default |
|---|---|---|
filters | { name: string; operator: FilterOperatorTypes; value: any; }[] | - |
sort | { key: string; order: "asc" | "desc"; }[] | - |
group_by | string[] | - |
search | string | - |
DataTableColumn Interface
| Prop | Type | Default |
|---|---|---|
accessorKey | string | - |
header | string | - |
columnType | "number" | "text" | "date" | "select" | - |
enableSorting | boolean | - |
enableColumnFilter | boolean | - |
enableHiding | boolean | - |
enableGrouping | boolean | - |
filterOptions | FilterSelectOption[] | - |
defaultHidden | boolean | - |
DataTable.Content Props
| Prop | Type | Default |
|---|---|---|
emptyState | ReactNode | - |
zeroState | ReactNode | - |
classNames | { root?: string | undefined; table?: string | undefined; header?: string | undefined; body?: string | undefined; row?: string | undefined; } | - |
Examples
Basic Usage
Column Configuration
Columns can be configured with various options:
Filtering
The DataTable supports multiple filter types:
Filter types:
- Text: equals, not equals, contains,
- Number: equals, not equals, less than, less than or equal, greater than, greater than or equal
- Date: equals, not equals, before, on or before, after, on or after
- Select: equals, not equals
Sorting
Enable column sorting:
Grouping
Group rows by same column data:
Server-side Integration
Custom Styling
Custom Cell Rendering
Using DataTable Filter
The DataTable.Filters component can be used separately to filter data for custom views.
Using DataTable Search
The DataTable.Search component provides search functionality that automatically integrates with the table query. By default, it is disabled in zero state (when no data and no filters/search applied).
Search Auto-Disable Behavior
By default, DataTable.Search is automatically disabled in zero state to provide a better user experience. You can override this behavior:
The search will be automatically enabled when:
- Data exists in the table
- Filters are applied
- A search query is already present
Empty States
The DataTable supports two types of empty states to provide better user experience:
Zero State
Zero state is shown when no data has been fetched initially (no filters or search applied). In this state, the filter bar is automatically hidden.
Empty State
Empty state is shown when initial data exists but no results match after applying filters or search. In this state, the filter bar remains visible so users can adjust their filters.
Fallback Behavior
- If
zeroStateis not provided, it falls back toemptyState - If neither
zeroStatenoremptyStateis provided, a default empty state is shown - The filter bar visibility is automatically controlled based on the state
Custom Empty State Content
You can provide custom React components for both states: