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.
pnpm dlx shadcn@latest add @gridcn/data-grid-cell-types-demo
What the demo shows
- A column with no
typeedits liketextand sorts numeric-aware, soitem2sorts beforeitem10. readOnly: trueon a column refuses edits, pastes, and fills for its cells.numberwithoptions: { min: 18, max: 100 }clamps a typed or pasted value into that range. The Clamped column shows it.validateon anumbercolumn refuses a value and shows its message. The Validated column refuses an age under 18. On a column with bothminandvalidate, the clamp runs first, sovalidatesees the clamped value.numberwithoptions.formatshowsstyle: "currency"text. Copy, export, and the editor keep the raw number.checkbox,selectwithchoices, anddatewithdisplayFormatuse the other built-in editors.urlrenders a link. The link opens on Alt+Enter. The demo rows with ajavascript:value render as plain text.longTextopens a multi-line editor in a popover. Shift+Enter inserts a line break.renderCellon anumbercolumn draws a progress bar. Thenumbertype 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} />,
},
]);Related
- Built-in cell types: every type and its options
- Display override: the arguments of
renderCell - Custom cell type example: a type that none of these cover