gridcn2.0.0
Basic examples

Cell types example

Edit each built-in cell type in one grid, and see read-only, number clamping, and a renderCell override.

The grid has one column for each built-in cell type. Extra columns show a read-only column, number options, and a renderCell display override. Press Enter or F2 on a cell to open its editor.

Try each column's editor: Read-only refuses edits, Validated rejects an age under 18, Clamped moves a value into 18 to 100, Currency edits the raw number behind its locale format, Link opens with alt+Enter (its javascript: row stays plain text), Notes opens a multi-line editor, and renderCell shows a progress bar.

Text
Read-only
Validated
Clamped
Checkbox
Select
Date
Currency
Link
Notes
renderCell
Silent Tiger
user0@example.com
63
30
Viewer
Jul 5, 2023
$12.50
javascript:alert(1)
First line Second line Third line
4
Quick Lion
user1@example.com
67
39
Viewer
Apr 3, 2021
$15.67
Short note
89
Swift Wolf
user2@example.com
40
48
Manager
Oct 27, 2020
$18.84
Short note
80
Eager Lion
user3@example.com
50
57
User
Oct 8, 2022
$22.01
Short note
51
Eager Tiger
user4@example.com
45
66
Viewer
Oct 7, 2024
$25.18
javascript:alert(1)
Short note
83
Silent Wolf
user5@example.com
24
75
User
Jun 1, 2020
$28.35
First line Second line Third line
15
Swift Lion
user6@example.com
34
84
Viewer
Oct 18, 2022
$31.52
Short note
62
Eager Lion
user7@example.com
21
93
Manager
Oct 7, 2021
$34.69
Short note
42
pnpm dlx shadcn@latest add @gridcn/data-grid-cell-types-demo

What the demo shows

  • A column with no type edits like text and sorts numeric-aware, so item2 sorts before item10.
  • readOnly: true on a column refuses edits, pastes, and fills for its cells.
  • number with options: { min: 18, max: 100 } clamps a typed or pasted value into that range. The Clamped column shows it.
  • validate on a number column refuses a value and shows its message. The Validated column refuses an age under 18. On a column with both min and validate, the clamp runs first, so validate sees the clamped value.
  • number with options.format shows style: "currency" text. Copy, export, and the editor keep the raw number.
  • checkbox, select with choices, and date with displayFormat use the other built-in editors.
  • url renders a link. The link opens on Alt+Enter. The demo rows with a javascript: value render as plain text.
  • longText opens a multi-line editor in a popover. Shift+Enter inserts a line break.
  • renderCell on a number column draws a progress bar. The number type still handles editing, paste, and sort. Display override shows the code.

The column list of the demo, shortened:

import { defineColumns } from "@/components/data-grid/data-grid";

type Person = { id: string; name: string; email: string; level: number };

export const columns = defineColumns<Person>()([
  { id: "name", header: "Text", accessorKey: "name" },
  { id: "email", header: "Read-only", accessorKey: "email", readOnly: true },
  {
    id: "level",
    header: "Clamped",
    accessorKey: "level",
    type: "number",
    options: { min: 18, max: 100 },
    renderCell: ({ value }) => <progress max={100} value={value ?? 0} />,
  },
]);

On this page