Skip to content
Browse docs and components

Data Table

data-table

A typed table with sortable headers, search, row selection with bulk actions and paging. Columns are data and every cell is yours to render. A sticky header, aria-sort, an indeterminate select-all, and a selection that survives sorting.

Responsive

Install

$npxshadcnadd@forme/data-table

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { DataTable, type DataTableColumn } from "@/components/forme/data-table/data-table";

const columns: DataTableColumn<Invoice>[] = [
  { id: "customer", header: "Customer", cell: (row) => row.customer, sortValue: (row) => row.customer },
  { id: "amount", header: "Amount", cell: (row) => money(row.amount), align: "end" },
];

<DataTable label="Invoices" rows={invoices} columns={columns} getRowId={(row) => row.id} selectable />

When to use

Reach for it

  • Screens that are mostly a table, where people sort, search, select and page through rows.

Use something else

  • Thousands of rows: it sorts and pages on the client. Keep the markup and move the sorting and paging to the server.
  • Small read-only lists, where a plain table is simpler.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

DataTable

A table for the screens that are mostly a table: sort, search, select, page.

PropTypeDefaultDescription
rows*readonly Row[]—
columns*readonly DataTableColumn<Row>[]—
getRowId*(row: Row) => string—
label*string—Accessible name for the table.
selectablebooleanfalseAdds a checkbox column. Selection is reported by id.
onSelectionChange(ids: string[]) => void—
selectionActions(ids: string[]) => ReactNode—Rendered in the toolbar while rows are selected — bulk actions go here.
searchText(row: Row) => string—Adds a search field that matches against this text.
pageSizenumber—Rows per page. Omit to show everything.
emptyReactNode"No results."Shown when there are no rows, or none match the search.
classNamestring—

Accessibility

  • The sorted header carries aria-sort, and select-all is indeterminate when only some rows are picked.
  • The selection count is announced as it changes.

Responsive behaviour

  • Columns marked hideOnMobile drop below sm, and the search field goes full width.
  • The header sticks while the body scrolls.