Installation
Usage
"use client"
import { DataGrid, type GridColumn } from "@/components/data-grid"
type Order = { id: string; customer: string; status: string; total: number }
const columns: GridColumn<Order>[] = [
{ key: "id", header: "Order", frozen: true },
{ key: "customer", header: "Customer", editable: true },
{ key: "status", header: "Status", type: "select", options: ["Paid", "Pending"], editable: true },
{ key: "total", header: "Total", type: "number", aggregate: "sum", editable: true },
]
const rows: Order[] = [
{ id: "A-1001", customer: "Emily Carter", status: "Paid", total: 120 },
{ id: "A-1002", customer: "James Walker", status: "Pending", total: 80 },
]
export function Orders() {
return <DataGrid label="Orders" columns={columns} defaultRows={rows} getRowId={(row) => row.id} />
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | GridColumn[] | — | Each column: key, header, type (text, number, date, select), editable, frozen, hidden, aggregate, format, render, validate. |
| rows / defaultRows | T[] | [] | The data, kept by you or by the grid. |
| onRowsChange | (rows, changes) => void | — | Called after every edit, paste, fill, undo or redo, with exactly what changed. |
| getRowId | (row, index) => string | position | A stable id for each row. |
| label | string | — | Accessible name. |
| height | number | 480 | Height in pixels; rows and columns outside it aren't drawn. |
| rowHeight | number | 36 | Row height in pixels. |
| defaultGroupBy | string[] | [] | Columns to group by at the start, outermost first. |
| toolbar | boolean | true | Search, Columns, Group, Undo and Export. |
| selectable | boolean | false | A checkbox on each row. |
| onSelectedRowsChange | (ids: string[]) => void | — | Called when the ticked rows change. |
| emptyMessage | ReactNode | — | Shown when nothing matches. |
Accessibility
- Follows the ARIA grid pattern: arrow keys, Home, End, Page Up and Page Down move, and every cell reports its row and column.
- Enter, F2 or typing edits a cell; Escape cancels; a refused value says why, next to the cell.
- Shift + arrows selects a range; Ctrl+C, Ctrl+X and Ctrl+V copy, cut and paste; Ctrl+Z and Ctrl+Y undo and redo.
- Sorting, filtering, grouping, copying and edits are announced to screen readers.
- On touch, tap selects, tap again edits and a long press starts a range.
Changelog
- v1.0.1Latest
Fix: the page no longer pauses while a big grid gets ready. Columns reach the worker in slices of a few milliseconds, in idle time or first for the sort or search that needs them, so even the first keystroke on a slow phone stays smooth.
- v1.0.0
First release.