Data Table
Headless TanStack Table v8 wrapped around Clay's Table primitives, with sortable headers, optional row selection, and pagination out of the box.
Install
Pull Data Table from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { DataTable } from "@brika/clay";import { DataTable } from "@brika/clay/components/data-table";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
'use client';
import { DataTable } from '@brika/clay/components/data-table';
import { basicColumns, paymentRows } from '../data-table.demo-data';
/** Compact invoice table, no sorting or pagination, status badges + right-aligned currency cells. */
export default function DataTableBasicDemo() {
return <DataTable columns={basicColumns} data={paymentRows} enableSorting={false} pageSize={0} />;
}Data Table, every way
Accessibility
- Sortable column headers expose the current sort direction via
aria-sort("ascending", "descending", or "none"). - The sort toggle is rendered as a real
<button>so it is reachable by keyboard and announces its label to AT. - Selected rows carry
data-state="selected"; provide anaria-labelon the row checkbox that names the row. - Use
<TableCaption>from the underlyingTableto give the data table an accessible name when needed.
Theme tokens
Every CSS variable Data Table reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Data Table
without touching component code.
Data Table tokens
2 tokens--data-table-sort-indicator-colorcolorvar(--muted-foreground)components.dataTable.sortIndicatorColorColor of the chevron rendered next to a sortable column header (asc / desc / unsorted).
--data-table-selected-row-bgcolorvar(--accent)components.dataTable.selectedRowBgBackground fill applied to a row when it is selected via the row-selection checkbox.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.dataTable, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"dataTable": {
"sortIndicatorColor": "var(--muted-foreground)"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-data-table-…) — see the
chips on each token row.
API reference
Props specific to Data Table. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.
<DataTable />
8 props- ColumnDef<TData, TValue>[]TanStack column definitions. Use
accessorKey,accessorFn, orid. - TData[]Source rows. Reference identity is used for memoisation, keep it stable.
- stringForwarded to the underlying
<Table>. - emptyMessagedefault
'No results.'React.ReactNodeOptional empty-state message rendered whendataresolves to zero rows. - enableRowSelectiondefault
falsebooleanWire up row selection state. Add a checkbox column yourself incolumns. - enableSortingdefault
truebooleanToggle sorting model + sort UI on column headers. Defaults to true. - (row: Row<TData>) => voidFired when a body row is clicked (excludes header rows).
- pageSizedefault
10numberPage size for built-in pagination. Defaults to 10. Pass 0 to disable pagination.
<DataTableColumnHeader />
1 prop- Column<TData, TValue>The TanStack
Columninstance, given to you by theheaderrender prop.