"use client";
import { DataTable } from "@pixxl-tools/components";| Prop | Type | Default | Description |
|---|---|---|---|
columns (required) | readonly DataTableColumn<Row>[] | — | Column definitions: accessor (a key of Row) or cell(row). |
rowId (required) | (row: Row, index: number) => string | — | Stable id of a row (selection, expansion and React keys use it). |
rows (required) | readonly Row[] | — | The data; Row is inferred from it. |
batchActions | ReactNode | — | Shown with the selected count while rows are selected. |
columnVisibility | Readonly<Record<string, boolean>> | — | Hide columns by id ({ email: false }). |
defaultExpandedRows | readonly string[] | — | Expanded row ids when uncontrolled. |
defaultSelectedRows | readonly string[] | — | Selected row ids when uncontrolled (shows the selection column). |
defaultSort | DataTableSort | null | — | Sort when uncontrolled. Uncontrolled sorting also orders the rows (by the column's accessor); with sort you pass rows already sorted. |
density | PixxlDensity | comfortable | Row height (default comfortable). |
empty | ReactNode | "No rows" from the catalog | Shown when there are no rows (default "No rows" from the catalog). |
columnsrequiredreadonly DataTableColumn<Row>[]
Column definitions: accessor (a key of Row) or cell(row).
rowIdrequired(row: Row, index: number) => string
Stable id of a row (selection, expansion and React keys use it).
rowsrequiredreadonly Row[]
The data; Row is inferred from it.
batchActionsReactNode
Shown with the selected count while rows are selected.
columnVisibilityReadonly<Record<string, boolean>>
Hide columns by id ({ email: false }).
defaultExpandedRowsreadonly string[]
Expanded row ids when uncontrolled.
defaultSelectedRowsreadonly string[]
Selected row ids when uncontrolled (shows the selection column).
defaultSortDataTableSort | null
Sort when uncontrolled. Uncontrolled sorting also orders the rows (by the column's accessor); with sort you pass rows already sorted.
densitydefault comfortablePixxlDensity
Row height (default comfortable).
emptydefault "No rows" from the catalogReactNode
Shown when there are no rows (default "No rows" from the catalog).
Other props are passed to the root element (HTMLAttributes<HTMLTableElement>), including className, style, id and aria-* attributes.
| Alpha |
type Row = { id: string; name: string };
const rows: Row[] = [{ id: "a", name: "Alpha" }, { id: "b", name: "Beta" }];
const columns = [{ id: "name", header: "Name", cell: (row: Row) => row.name, sortable: true }];
<DataTable columns={columns} rows={rows} rowId={(row) => row.id} />