Composed
Data table
Table built from rows and column definitions, with sorting, selection, expandable rows, row links and loading and empty states.
import { DataTable, type DataTableColumnDef } from "@openperf/deft";
const columns: DataTableColumnDef<Release>[] = [
{
id: "version",
header: "Release",
cell: ({ row }) => row.original.version,
meta: { kind: "title" },
},
{
id: "deploys",
accessorFn: (row) => row.deploys,
header: "Deploys",
cell: ({ row }) => row.original.deploys,
meta: { kind: "number", width: 96 },
},
];
<DataTable aria-label="Releases" columns={columns} data={releases} />;When to use
| Need | Component |
|---|---|
| Records that share the same columns, with sorting, selection, expansion or states | Data table |
| Rows that do not share one shape: full-width rows, per-row cell tones | Table |
| Short list of items with a label, a description and actions, such as members or tokens | List |
Columns
A column is a TanStack Table column definition with an id, a header and a cell render function; row.original is your row object. A cell lays its content out in a row with an 8px gap, so it can return several elements.
Deft reads its own options from meta. kind presets the alignment, tone, weight and stacked area; the other meta options override single properties.
| Kind | Alignment | Text | area | Use |
|---|---|---|---|---|
title | Start | Medium weight | title | Main column of the row; holds the row link. |
text | Start | Default | meta | Any other text. The default kind. |
number | End, tabular numerals | secondary tone | meta | Counts and measurements. |
date | End, tabular numerals | icon tone | aside | Timestamps. |
actions | End | Default | aside | A row menu or buttons. |
Widths and narrow containers
A column without width shares the free space equally. A number is a width in pixels and a string is any CSS grid track. The layout follows the width of the container, not of the viewport:
| Container width | Layout |
|---|---|
52rem and up | All columns at their width. |
Below 52rem | Columns with priority: "low" are hidden; compactWidth replaces width where set. |
Below 36rem | Rows stack: the header and priority: "medium" columns are hidden too, and number columns show their header as an inline label. |
Table describes where each area goes in a stacked row.
Row IDs
Every row needs a stable string ID. DataTable reads row.id when it is a string; for any other row type getRowId is a required prop. The IDs are the values of selection.selected.
Sorting, selection and links
sorting and selection are controlled. DataTable does not reorder rows, so sort data yourself. Only a column with an accessor gets a sortable header, one column sorts at a time, and the first click sorts descending while each next click flips the direction.
selection adds a checkbox column and a header checkbox that selects or clears all rows. Shift-click a row checkbox to select the range from the row toggled last. Pair it with an Action bar for bulk actions.
link returns the link props of a row: an href, or render with a router link. The link renders in the title column and stretches over the whole row, while the checkbox stays clickable.
Expandable rows
renderDetail adds a chevron to each row and renders its result in a panel under an open row. A click anywhere in the row toggles it, several rows can be open at once, and onRowClick is ignored.
Loading and empty states
While pending is set, loadingRows skeleton rows replace the body. When data is empty and pending is not set, the empty state is shown; without empty, an empty table renders only its header.
API
DataTable
Generic over the row type TData. Name the table with aria-label. ArrowUp and ArrowDown move focus between row links, expand buttons or rows with onRowClick; on such a row Enter runs the handler and Space toggles its checkbox. The checkbox and expand labels are Lingui messages, so the table must render inside the root providers.
Prop
Type
DataTableColumnDef
The TanStack Table ColumnDef for the row type, with meta typed as DataTableColumnMeta. DataTable relies on these fields:
Prop
Type
DataTableColumnMeta
Prop
Type
DataTableSorting
Prop
Type
DataTableSelection
Prop
Type
DataTableEmpty
Rendered with the parts of Empty.
Prop
Type