Basic examples
Editable grid example
Edit seven columns of built-in cell types, select ranges, copy and paste, and drag the fill handle.
Press Enter or F2 on a cell to edit it. Drag over cells to select a range. Press Ctrl+C or Ctrl+V to copy and paste. Drag the fill handle to copy or continue a series.
pnpm dlx shadcn@latest add @gridcn/data-grid-demo
What the demo shows
- Seven columns use
text,number,checkbox,select, anddate. Thenumbercolumns setminandmax, theselectcolumn setschoices, and thedatecolumn setsdisplayFormat. defaultDataseeds twelve rows fromgenerateDemoRows(12). The demo keeps no state.DataGridProvider,DataGridRoot,DataGridHeader, andDataGridBodycompose the grid in parts.useDataGridFillreturns{ plugin }. The demo passespluginin thepluginsprop ofDataGridProvider. The plugin renders its own mount insideDataGridRoot, so the demo adds no child for it.- Range selection and the clipboard belong to the core. They need no add-on.
The provider with the fill add-on:
import {
DataGridBody,
DataGridHeader,
DataGridProvider,
DataGridRoot,
defineColumns,
} from "@/components/data-grid/data-grid";
import { useDataGridFill } from "@/components/data-grid-fill/data-grid-fill";
type Row = { id: string; name: string; age: number };
const columns = defineColumns<Row>()([
{ id: "name", header: "Name", accessorKey: "name" },
{ id: "age", header: "Age", accessorKey: "age", type: "number" },
]);
const rows: Row[] = [{ id: "1", name: "Ada", age: 36 }];
export function FillGrid() {
const { plugin } = useDataGridFill();
return (
<DataGridProvider defaultData={rows} columns={columns} plugins={[plugin]}>
<DataGridRoot className="h-60">
<DataGridHeader />
<DataGridBody />
</DataGridRoot>
</DataGridProvider>
);
}Related
- Fill handle: the add-on that this demo wires
- Clipboard: copy and paste behavior and its overrides
- Cell types example: one column per cell type