Data Grid
PronewA sortable, searchable, selectable and paginated table on TanStack Table, with the toolbar and footer already built.
| Author | ||||||
|---|---|---|---|---|---|---|
fix: focus ring in dark modemain | Ready | 0m 38s | Oct 12, 18:00 | DK | ||
feat: add RTL support to sidebarfeat/rtl | Ready | 1m 15s | Oct 12, 17:13 | MS | ||
docs: theming guidedocs/theming | Canceled | 1m 52s | Oct 12, 16:26 | AK | ||
chore: bump radix-uimain | Building | 2m 29s | Oct 12, 15:39 | JL | ||
feat: data grid density togglefeat/density | Ready | 0m 46s | Oct 12, 14:52 | DK | ||
fix: combobox keeps selection on blurfix/combobox | Ready | 1m 23s | Oct 12, 14:05 | MS |
36 rows
Installation
npx shadcn@latest add @blank-pro/data-gridNeeds a Blank Pro licence key and the @blank-pro registry. Set up Pro access
Usage
import {
createDataGridColumnHelper,
DataGrid,
DataGridColumnHeader,
DataGridPagination,
DataGridSearch,
DataGridSelectAll,
DataGridSelectRow,
DataGridTable,
DataGridToolbar,
DataGridViewOptions,
useDataGrid,
} from "@/components/ui/data-grid"const column = createDataGridColumnHelper<Deployment>()
const columns = column.columns([
column.display({
id: "select",
header: ({ table }) => <DataGridSelectAll table={table} />,
cell: ({ row }) => <DataGridSelectRow row={row} />,
enableSorting: false,
enableHiding: false,
}),
column.accessor("commit", {
header: ({ column }) => <DataGridColumnHeader column={column} title="Commit" />,
}),
column.accessor("duration", {
header: ({ column }) => <DataGridColumnHeader column={column} title="Duration" />,
meta: { align: "end" },
}),
])
export function Deployments({ data }: { data: Deployment[] }) {
const table = useDataGrid({ data, columns, getRowId: (row) => row.id })
return (
<DataGrid table={table}>
<DataGridToolbar>
<DataGridSearch />
<DataGridViewOptions className="ml-auto" />
</DataGridToolbar>
<DataGridTable />
<DataGridPagination />
</DataGrid>
)
}useDataGrid is TanStack Table v9's useTable with the features a grid needs
already registered: sorting, a global filter, column visibility, row selection
and pagination. Everything else — initialState, controlled state with its
on…Change callback, manualPagination for server data — is passed straight
through. Define columns at module scope or memoise them, along with data;
new arrays every render re-run every row model.
DataGrid puts the table in context, so each part is a single element and you
arrange them as you like. The markup is Blank's Table.
Column headers are menus: sort ascending or descending, clear the sort, or hide
the column, with aria-sort on the header cell. The search waits 150ms after
typing before filtering, and Escape clears it; a search with no matches says so
and offers to clear it. Shift-click on a row checkbox selects the range from
the last row you clicked.
Column meta takes align ("start", "center" or "end"), a label for
the column menu when the header is not a string, and headerClassName and
cellClassName.
Examples
Loading and empty
loading swaps the rows for skeletons and disables paging. empty on
DataGridTable replaces the message shown when there are no rows at all.
3 rows
API Reference
useDataGrid
Takes TanStack useTable options except features; returns the table.
globalFilterFn defaults to "includesString" and the page size to 10.
createDataGridColumnHelper
createDataGridColumnHelper<TData>() returns a column helper typed for the
grid's features, including its column meta.
DataGrid
div props, plus:
| Prop | Type | Default |
|---|---|---|
table | the result of useDataGrid | — |
loading | boolean | false |
density | "compact" | "default" | "comfortable" | — |
defaultDensity | "compact" | "default" | "comfortable" | "default" |
onDensityChange | (density) => void | — |
DataGridToolbar
div props, with role="toolbar".
DataGridSearch
InputGroupInput props, plus:
| Prop | Type | Default |
|---|---|---|
debounce | number (ms) | 150 |
DataGridViewOptions
Button props. Lists every column that can be hidden.
DataGridDensityToggle
ToggleGroup props, without its value props — density lives on DataGrid.
DataGridColumnHeader
| Prop | Type | Default |
|---|---|---|
column | Column | — |
title | string | — |
DataGridSelectAll, DataGridSelectRow
Checkboxes for a select column. DataGridSelectAll takes the header's
table; DataGridSelectRow takes the cell's row.
DataGridTable
Table props, plus:
| Prop | Type | Default |
|---|---|---|
empty | ReactNode | "No rows yet." |
skeletonRows | number | the page size, up to 10 |
DataGridPagination
div props, plus:
| Prop | Type | Default |
|---|---|---|
pageSizes | number[] | [10, 20, 50] |