Data table
A typed table on your shadcn table: a columns API (show, hide, reorder, add custom), row actions (a non-empty `disabledReason` disables an entry and says why), rows that link through the provider's navigation, controlled or uncontrolled sorting, cursor pagination and loading, empty and error states (an error over rows keeps them, under an inline error).
Component: A piece you place inside your own screens: a table, a form, a card or a dialog. You decide the layout around it. Pages vs components
Ready to connect to Dolfin. Loads data through SDK hooks, with appearance and behaviour you can customise. Requires DolfinProvider.
Installation
Needs the Dolfin registry token. The CLI copies the source into your app.
bunx --bun shadcn@4.23.0 add @dolfin/base-data-tableAlso installs: table, button, dropdown-menu, base-states, base-info-hint, ui-base-data-table.
Usage
import { DataTable } from "@/components/dolfin/base/data-table";
// Place it anywhere inside your <DolfinProvider>.
<DataTable rows={rows} columns={columns} getRowId={getRowId} />Renders inside DolfinProvider (set it up once). By default it loads its own data through the SDK. Supplied-data examples show how to override that behavior.
API reference
| Prop | Type | Description |
|---|---|---|
rows required | readonly T[] | `undefined` while the first page loads. |
columns required | readonly DataTableColumn<T>[] | |
getRowId required | (row: T, index: number) => string | |
columnOrder | readonly string[] | Column ids to show first, in this order. |
columnVisibility | Readonly<Record<string, boolean>> | Show or hide columns by id, overriding each column's `hidden`. |
rowActions | readonly DataTableRowAction<T>[] | ((row: T) => ReactNode) | Menu entries per row, or a render function for custom controls. |
rowActionsLabel | string | ((row: T) => string) | Accessible name of the row actions button ("Bill actions"). |
actionsHeader | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | The row actions column's header. Defaults to "Actions" for screen readers only. |
isRowBusy | (row: T) => boolean | Shows a spinner on the row's actions while one of them runs. |
onRowClick | (row: T) => void | Called when a row is activated (a click on it, or its primary cell, which becomes a button). Given, it always fires and replaces the row's link: `getRowRoute` is then not followed. |
getRowRoute | (row: T) => DolfinRoute | null | undefined | Without `onRowClick`, links rows to a Dolfin route: the primary cell (`primary: true`, else the first visible column) renders a real anchor through the provider's navigation, and a click anywhere else on the row follows it (Cmd, Ctrl, Shift or middle click opens a new tab). A route the host does not serve leaves a plain row. |
rowClassName | (row: T) => string | undefined | |
sort | DataTableSort | Controlled sort; pair with `onSortChange`. |
defaultSort | DataTableSort | |
onSortChange | (sort: DataTableSort | null) => void | |
manualSorting | boolean | The rows arrive sorted (server-side); never sort on the client. |
pagination | DataTablePagination | |
loading | boolean | |
loadingLabel | string | |
error | {} | |
onRetry | () => void | |
emptyState | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | Replaces the default empty state (e.g. "No bills match these filters"). |
emptyTitle | string | |
emptyDescription | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | |
caption | string | Accessible name of the table. |
className | string | |
variant | DataTableVariant | |
classNames | DataTableClassNames | |
pager | boolean | Show the built-in previous / next pager when there is more than one page. Default true; pass false when you draw your own pager from the list's pagination (the table still dims while a page loads). |
onRowHover | (row: T | null) => void | Called with the row the pointer moves onto, and with `null` when the pointer leaves the rows (e.g. to highlight the row's point in a chart next to the table). Moving between rows reports the new row without a `null` first. |
Customisation
Without editing the source, you can change:
- Class names
rowClassNameclassNameclassNames.frameclassNames.headerclassNames.headerCellclassNames.rowclassNames.cellclassNames.pager- Messages
base.dataTablebase.infoHintbase.statescore.errors
Or edit the installed file directly: it is your code. See theming for colours and fonts.
Hooks
The SDK hooks this component uses. Use them directly from @dolfinai/react to build your own version.
useDolfinHasRouteuseDolfinHrefuseDolfinNavigateuseMessagesFiles
Written to your app by the install command:
components/dolfin/base/data-table.tsx322 linescomponents/dolfin/base/data-table-pager.tsx16 linescomponents/dolfin/base/data-table-row-actions.tsx30 linescomponents/dolfin/base/data-table-columns.ts2 lines