dolfindevelopers

Data table

ComponentFoundationsSDK + UI

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

Choose your integration

Ready to connect to Dolfin. Loads data through SDK hooks, with appearance and behaviour you can customise. Requires DolfinProvider.

Loading preview…

Installation

Needs the Dolfin registry token. The CLI copies the source into your app.

Terminal
bunx --bun shadcn@4.23.0 add @dolfin/base-data-table

Also installs: table, button, dropdown-menu, base-states, base-info-hint, ui-base-data-table.

Usage

screen.tsx
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

PropTypeDescription
rows requiredreadonly T[]`undefined` while the first page loads.
columns requiredreadonly DataTableColumn<T>[]
getRowId required(row: T, index: number) => string
columnOrderreadonly string[]Column ids to show first, in this order.
columnVisibilityReadonly<Record<string, boolean>>Show or hide columns by id, overriding each column's `hidden`.
rowActionsreadonly DataTableRowAction<T>[] | ((row: T) => ReactNode)Menu entries per row, or a render function for custom controls.
rowActionsLabelstring | ((row: T) => string)Accessible name of the row actions button ("Bill actions").
actionsHeaderstring | 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) => booleanShows a spinner on the row's actions while one of them runs.
onRowClick(row: T) => voidCalled 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 | undefinedWithout `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
sortDataTableSortControlled sort; pair with `onSortChange`.
defaultSortDataTableSort
onSortChange(sort: DataTableSort | null) => void
manualSortingbooleanThe rows arrive sorted (server-side); never sort on the client.
paginationDataTablePagination
loadingboolean
loadingLabelstring
error{}
onRetry() => void
emptyStatestring | 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").
emptyTitlestring
emptyDescriptionstring | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re…
captionstringAccessible name of the table.
classNamestring
variantDataTableVariant
classNamesDataTableClassNames
pagerbooleanShow 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) => voidCalled 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.

useDolfinHasRouteuseDolfinHrefuseDolfinNavigateuseMessages

Files

Written to your app by the install command:

  • components/dolfin/base/data-table.tsx 322 lines
  • components/dolfin/base/data-table-pager.tsx 16 lines
  • components/dolfin/base/data-table-row-actions.tsx 30 lines
  • components/dolfin/base/data-table-columns.ts 2 lines