Data Table
A feature-rich data table built on TanStack Table and shadcn/ui's Table primitives. Supports sorting, column filtering, pagination, row selection, column visibility toggling, and row actions out of the box.
Demo
All features active: type in the filter box to search by email, click column headers to sort, open the Columns menu to toggle visibility, tick checkboxes to select rows, and use the ⋯ button on any row for row-level actions.
Amount | ||||
|---|---|---|---|---|
| pending | alice@example.com | $100.00 | ||
| processing | bob@example.com | $125.00 | ||
| success | carol@example.com | $250.00 | ||
| failed | dave@example.com | $85.00 | ||
| success | eve@example.com | $310.00 | ||
| pending | frank@example.com | $45.00 | ||
| processing | grace@example.com | $780.00 | ||
| success | heidi@example.com | $200.00 | ||
| failed | ivan@example.com | $55.00 | ||
| pending | judy@example.com | $430.00 |
0 of 12 row(s) selected.
Page 1 of 2
Design Guidelines
Do
- Define columns outside the component. Placing
columnsoutside the render function prevents the array reference from changing on every render. - Use server-side models for large datasets. Pass
manualPaginationandmanualSortingto TanStack Table and fetch data from a server action or API route. - Provide stable row IDs. Use
getRowIdto keep selection state stable across pagination and re-fetches.
Don't
- Don't define columns inline. Inline column definitions recreate the array on every render, causing unnecessary reconciliation work.
- Don't load thousands of rows client-side. Client-side filtering and sorting works well for small datasets; switch to server-side models for large ones.
- Don't skip accessible labels on icon buttons. Checkbox columns and icon-only action buttons need
aria-labelorsr-onlytext.
Developer Reference
DataTable Props
- data
- Array of row data objects.
- columns
- TanStack ColumnDef<TData, TValue>[] array.
- filterColumn?
- Accessor key of the column to filter on.
- filterPlaceholder?
- Placeholder text for the filter input. Default: "Filter..."
Built-in Column Features
- Sorting — call
column.toggleSorting()in the header render function. - Column hiding — set
enableHiding: falseto pin a column in the Columns menu. - Row selection — use
id: "select"withenableSorting: falseandenableHiding: false. - Row actions — use
id: "actions"with aDropdownMenuin the cell renderer.