Data Table
A powerful and flexible data table component for displaying, filtering, sorting, and paginating tabular data.
Installation
Install the components and dependencies:
Wrap your application with the NuqsAdapter
for query state management:
Layout
Import the components and compose them together:
Sort List
The DataTableSortList
provides a comprehensive way to sort data by multiple columns simultaneously.
Features
- Supports multiple column sorting
- Drag and drop reordering
- Ascending and descending directions
Installation
Filter List
The DataTableFilterList
provides a comprehensive way to filter data with multiple conditions.
Features
- Multiple filter conditions with AND/OR logic
- Drag and drop reordering
- Dynamic operators per field type
Installation
Filter Menu
The DataTableFilterMenu
provides a command palette-style interface for quickly adding and managing filters.
Features
- Command palette-style interface
- Context-aware input fields
- Compact token display
Installation
Action Bar
The DataTableActionBar
provides a toolbar for the data table when rows are selected.
Features
- Floating action bar
- Customizable actions
- Row selection tracking
Installation
Walkthrough
Define columns with appropriate metadata:
Initialize the table state using the useDataTable
hook:
Pass the table instance to the DataTable
, and DataTableToolbar
components:
For advanced filtering, use the DataTableAdvancedToolbar
component:
Alternatively, swap out DataTableFilterList
with DataTableFilterMenu
for a command palette-style interface:
Render an action bar on row selection:
API Reference
Column Definitions
The column definitions are used to define the columns of the data table.
Properties
Core configuration options for defining columns.
Prop | Description |
---|---|
id | Required: Unique identifier for the column |
accessorKey | Required: Key to access the data from the row |
accessorFn | Optional: Custom accessor function to access data |
header | Optional: Custom header component with column props |
cell | Optional: Custom cell component with row props |
meta | Optional: Meta options for accessing column metadata |
enableColumnFilter | By default, the column will not be filtered. Set to `true` to enable filtering |
enableSorting | Enable sorting for this column |
enableHiding | Enable column visibility toggle |
Column Meta
Column meta options for filtering, sorting, and view options.
Prop | Description |
---|---|
label | The display name for the column |
placeholder | The placeholder text for filter inputs |
variant | The type of filter to use (`text`, `number`, `select`, etc.) |
options | For select/multi-select filters, an array of options with `label`, `value`, and optional `count` and `icon` |
range | For range filters, a tuple of `[min, max]` values |
unit | For numeric filters, the unit to display (e.g., 'hr', '$') |
icon | The react component to use as an icon for the column |
Filter Variants
Available filter variants for column meta.
Title | Description |
---|---|
text | Text search with contains, equals, etc. |
number | Numeric filters with equals, greater than, less than, etc. |
range | Range filters with minimum and maximum values |
date | Date filters with equals, before, after, etc. |
dateRange | Date range filters with start and end dates |
boolean | Boolean filters with true/false values |
select | Single-select filters with predefined options |
multiSelect | Multi-select filters with predefined options |
Reference the TanStack Table Column Definitions Guide for detailed column definition guide.
useDataTable
A hook for initializing the data table with state management.
Prop | Type | Default |
---|---|---|
history? | "push" | "replace" | "replace" |
debounceMs? | number | 300 |
throttleMs? | number | 50 |
clearOnDefault? | boolean | false |
enableAdvancedFilter? | boolean | false |
scroll? | boolean | false |
shallow? | boolean | true |
startTransition? | TransitionStartFunction | - |
pageCount | number | - |
data | TData[] | - |
columns | ColumnDef<TData, any>[] | - |
getRowId? | (originalRow: TData, index: number, parent?: Row<TData> | undefined) => string | - |
defaultColumn? | Partial<ColumnDef<TData, unknown>> | - |
initialState? | InitialTableState | - |
DataTable
The main data table component.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
actionBar? | ReactNode | - |
DataTableColumnHeader
Custom header component for columns with sorting.
Prop | Type | Default |
---|---|---|
column | Column<TData, TValue> | - |
title | string | - |
DataTableToolbar
Standard toolbar with filtering and view options.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
DataTableAdvancedToolbar
Advanced toolbar with more comprehensive filtering capabilities.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
DataTableViewOptions
Controls column visibility and display preferences in the data table.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
DataTableSortList
List of applied sorting with ability to add, remove, and modify sorting.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
debounceMs? | number | 300 |
throttleMs? | number | 50 |
shallow? | boolean | true |
DataTableFilterList
List of applied filters with ability to add, remove, and modify filters.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
debounceMs? | number | 300 |
throttleMs? | number | 50 |
shallow? | boolean | true |
DataTableFilterMenu
Filter menu with ability to add, remove, and modify filters.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
debounceMs? | number | 300 |
throttleMs? | number | 50 |
shallow? | boolean | true |
DataTableActionBar
Floating action bar component for actions for selected rows.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
visible? | boolean | - |
container? | Element | DocumentFragment | document.body |
DataTablePagination
Pagination controls for the data table.
Prop | Type | Default |
---|---|---|
table | Table<TData> | - |
pageSizeOptions? | number[] | [10, 20, 30, 40, 50] |
Accessibility
Keyboard Interactions
Key | Description |
---|---|
F | Opens the filter menu. |
Shift + F | Removes the last applied filter. |
S | Opens the sort menu. |
Shift + S | Removes the last applied sort. |
BackspaceDelete | Removes the focused filter/sort item. Removes the last applied filter/sort when menu trigger is focused. |
Credits
- shadcn/ui - For the initial implementation of the data table.