gridcn2.0.0
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.

Name
Email
Age
Active
Role
Joined
Score
Silent Tiger
user0@example.com
63
Viewer
Jul 5, 2023
4
Quick Lion
user1@example.com
67
Viewer
Apr 3, 2021
89
Swift Wolf
user2@example.com
40
Manager
Oct 27, 2020
80
Eager Lion
user3@example.com
50
User
Oct 8, 2022
51
Eager Tiger
user4@example.com
45
Viewer
Oct 7, 2024
83
Silent Wolf
user5@example.com
24
User
Jun 1, 2020
15
Swift Lion
user6@example.com
34
Viewer
Oct 18, 2022
62
Eager Lion
user7@example.com
21
Manager
Oct 7, 2021
42
Eager Eagle
user8@example.com
25
Editor
Jun 11, 2024
35
Bold Tiger
user9@example.com
19
Editor
Mar 20, 2024
52
Bold Bear
user10@example.com
42
User
Apr 16, 2020
28
Swift Wolf
user11@example.com
47
Manager
Aug 4, 2022
9
pnpm dlx shadcn@latest add @gridcn/data-grid-demo

What the demo shows

  • Seven columns use text, number, checkbox, select, and date. The number columns set min and max, the select column sets choices, and the date column sets displayFormat.
  • defaultData seeds twelve rows from generateDemoRows(12). The demo keeps no state.
  • DataGridProvider, DataGridRoot, DataGridHeader, and DataGridBody compose the grid in parts.
  • useDataGridFill returns { plugin }. The demo passes plugin in the plugins prop of DataGridProvider. The plugin renders its own mount inside DataGridRoot, 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>
  );
}

On this page