import { DataTable, type DataTableColumn } from "@crispy-seed/data-table";
DataTable is published as the standalone @crispy-seed/data-table package — install it with bun add @crispy-seed/data-table (or npm install / pnpm add). It is a directly imported component, so no registry copy or CLI add step is required.
Columns are passed as columns: DataTableColumn<TRow>[], and rows are passed as data: TRow[]. TRow must have id: string (selection/sorting/editing identify rows by this id).
The type of each column determines how it is displayed (if render is provided, it is used instead of this default renderer). If omitted, "text" is used.
type
Display
text (default)
plain string
entity
seed Avatar(20px) + weight-500 name. If onOpenPreview is provided, a "preview" icon appears on hover and focus
url / email
link style, no underline normally, underline only on hover
tags
one or more pills with consistently hashed color per value
status
single-value colored pill
number
right-aligned, tabular-nums
currency
right-aligned, tabular-nums, symbol (default "$") prefixed
date / datetime
locale formatted with locale (default "en-US")
rating
maxRating filled/empty stars (default 5)
checkbox
read-only or (editable) editable checkbox
The value itself is determined by value(row) — a single accessor shared by sorting, search, filter, and export. If omitted, row[key] is used as-is. Even with render, value is still used as the criterion for sorting/search/filter (only display is replaced by render).
Clicking the header of a column with sortable: true sorts it: the first click sorts in ascending order, and clicking the same column again changes it to descending order (toggles asc ↔ desc, with no third state to disable sorting entirely). Clicking a different sortable column starts that column in ascending order.
You can specify initial/controlled state with sort/onSortChange (controlled) or defaultSort (uncontrolled). If you specify any toolbarSorts in Toolbar below, those take priority over header click sorting.
Providing selectable adds a 40px checkbox column on the left, with a select-all checkbox in the header (indeterminate when partially selected) and checkboxes for each row. Supports selectedIds/onSelectionChange (controlled) or defaultSelectedIds (uncontrolled).
The toolbar provides free-text search (query, with searchable per column determining search eligibility), multi-condition sorting (toolbarSorts -- earlier conditions in the array take priority, later conditions only break ties), and filter as condition chips (toolbarFilters). Filter operators vary by column kind: default ("text") uses contains/doesnotcontain/startswith/endswith/is/isnot/empty/notempty, "number" uses is/isnot/lessthan/greaterthan/empty/notempty, "date" uses is/isnot/before/after/empty/notempty, "select" uses is/isnot/empty/notempty (+ if filterValues is present, a isanyof checkbox picker is also added). Date filters also offer Today / Tomorrow / Next week quick picks, and each row in the sort popover can be reordered with its drag handle.
By default filter chips are combined with AND. Turn on advancedToolbarFilter (or start open with defaultAdvancedToolbarFilter) to switch to the condition editor: a "Where" row followed by rows with an And / Or toggle, so you can build OR groups. The toggle is stored on each filter as connective ("and" by default, or "or").
Columns with editable: true open an editor on double-click -- if editor is not provided, they open text/number (depending on cellType) or date/datetime (cellType: "date"/"datetime") input, editor: "select" opens seed Select, and editor: "reference"/"actor" opens a searchable reference picker. editor: "switch" and type: "rating"/"checkbox" are always-live (immediate manipulation without double-click = instant commit).
Commits are passed to the table's onEdit(id, key, value). If it returns a Promise, the cell shows a pending state (spinner) during that time, and if it resolves, editing closes; if it rejects, it reverts to the last known value and shows a rejection message. The example below shows this rejection path when you enter "fail" as a value.
Cells are keyboard-navigable: arrow keys and Tab move between cells, Shift extends a range selection, and Enter opens the editor of an editable cell. On the primary cell (the first column, when it is an entity column) Enter calls that column's onOpenRecord. Ctrl/Cmd+C copies the active cell and shows a transient "Copying 1 cell..." notice; Ctrl/Cmd+V pastes into simple editable cells (plain text, number and date cells -- not select, rating, checkbox or tag cells).
Right-clicking a cell opens a menu with Copy, Paste, View edit history and Clear value. Paste and Clear value are disabled on read-only columns, and View edit history only appears when onViewEditHistory is passed. The primary cell keeps the browser's native menu.
"use client";import { DataTable, type DataTableColumn } from "@crispy-seed/data-table";import { useState } from "react";interface Contact { id: string; name: { name: string }; email: string; title: string; city: string; source: string;}const initialRows: Contact[] = [ { id: "c1", name: { name: "Ann Lee" }, email: "ann@example.com", title: "CEO", city: "Seoul", source: "Import", }, { id: "c2", name: { name: "Bo Park" }, email: "bo@example.com", title: "Designer", city: "Busan", source: "Web form", }, { id: "c3", name: { name: "Cy Kim" }, email: "cy@example.com", title: "Engineer", city: "Seoul", source: "Import", }, { id: "c4", name: { name: "Dee Choi" }, email: "dee@example.com", title: "Sales", city: "Daegu", source: "Referral", },];export default function DataTableKeyboardClipboard() { const [rows, setRows] = useState(initialRows); const [log, setLog] = useState( "Right-click a cell, or focus one and press Enter, Ctrl/Cmd+C or Ctrl/Cmd+V.", ); // The FIRST column is the primary cell: Enter on it calls `onOpenRecord`, and it keeps // the browser's native context menu. Title and City are editable; the rest are read-only, // so Paste and Clear value are disabled in their menu. const columns: DataTableColumn<Contact>[] = [ { key: "name", header: "Name", type: "entity", value: (row) => row.name.name, onOpenRecord: (row) => setLog(`Opened record: ${row.name.name}`), }, { key: "email", header: "Email", type: "email", editable: false }, { key: "title", header: "Title", editable: true }, { key: "city", header: "City", editable: true }, { key: "source", header: "Source", editable: false }, ]; return ( <div style={{ width: "100%", maxWidth: 760, padding: 24 }}> <p style={{ margin: "0 0 8px", fontSize: 13 }}>{log}</p> <DataTable columns={columns} data={rows} onEdit={(id, key, value) => setRows((prev) => prev.map((row) => (row.id === id ? { ...row, [key]: value } : row))) } onViewEditHistory={(row, columnKey) => setLog(`Edit history requested: ${row.id} / ${columnKey}`) } /> </div> );}
onEdit: receives edits, pastes and cleared values
editable: per column; editable: false marks a read-only column
onViewEditHistory(row, columnKey): adds "View edit history" to the menu
cellContextMenu (default true) and cellContextMenuItems: turn the menu off or append items
Providing summary: true per column adds a fixed summary footer row at the bottom, and clicking that column's trigger lets you choose an operation (count/filled count/sum/average, etc.). You can pre-set the starting operation with summaryDefaultOp, or if omitted, it starts empty with "Add calculation".
"use client";import { DataTable, type DataTableColumn } from "@crispy-seed/data-table";interface Deal { id: string; company: string; employees: number; arr: number;}const rows: Deal[] = [ { id: "1", company: "Google", employees: 182_000, arr: 307_000_000_000 }, { id: "2", company: "Stripe", employees: 8_000, arr: 16_000_000_000 }, { id: "3", company: "Figma", employees: 1_300, arr: 600_000_000 }, { id: "4", company: "Linear", employees: 60, arr: 30_000_000 },];// `summary` puts this column's ColumnCalc trigger in the sticky footer row --// rendered only because at least one column has it. `summaryDefaultOp` seeds// which operation shows before anyone opens the trigger's own menu.const columns: DataTableColumn<Deal>[] = [ { key: "company", header: "Company" }, { key: "employees", header: "Employees", type: "number", summary: true, summaryDefaultOp: "sum" }, { key: "arr", header: "ARR", type: "currency", summary: true, summaryDefaultOp: "average" },];export default function DataTableSummary() { return ( <div style={{ width: "100%", maxWidth: 760, padding: 24 }}> <DataTable columns={columns} data={rows} /> </div> );}
columnMenu enables a per-column menu in the header (rename / hide / move left·right). resizable (default true) allows dragging header boundaries to change width, and can be individually disabled per column with resizable: false. reorderable (default true) allows reordering columns by dragging headers. stickyFirst fixes the first column (or the selection column if present) during horizontal scroll, and setting actions: true on a column automatically fixes that column to the end without stickyLast -- the example below shows both simultaneously.
"use client";import { DataTable, type DataTableColumn } from "@crispy-seed/data-table";interface Row { id: string; name: string; a: string; b: string; c: string; d: string; e: string;}const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({ id: String(i), name: `Record ${i + 1}`, a: "Value A", b: "Value B", c: "Value C", d: "Value D", e: "Value E",}));// Explicit widths that sum past a normal viewport, so the container's own// `overflow-x: auto` is what reveals `stickyFirst` (the Name column) and the// `actions: true` trailing column, which is sticky-right on its own without// needing `stickyLast`.const columns: DataTableColumn<Row>[] = [ { key: "name", header: "Name", width: 200 }, { key: "a", header: "Column A", width: 220 }, { key: "b", header: "Column B", width: 220 }, { key: "c", header: "Column C", width: 220 }, { key: "d", header: "Column D", width: 220 }, { key: "e", header: "Column E", width: 220 }, { key: "actions", header: "", width: 48, resizable: false, actions: true },];export default function DataTableStickyColumns() { return ( <div style={{ width: "100%", maxWidth: 640, padding: 24 }}> <DataTable columns={columns} data={rows} stickyFirst columnMenu resizable reorderable /> </div> );}
columnManager adds an "Add column" button at the end of the header. It opens a searchable list of the hidden columns and puts the one you pick back in place. Columns become hidden through "Hide from view" in the column menu (columnMenu), or from the start with defaultHiddenColumnKeys. Headers can also carry glyphs: enriched shows a bolt (a string becomes its tooltip), and a pencil glyph marks editable: false columns when the table has onEdit.
With columnMenu on, the menu of a number column has a Formatting item for thousands grouping and decimal places, and a date / datetime column's menu switches between absolute and relative ("2 days ago") dates. Formats only change the display, not the value used for sorting, filtering or export.
"use client";import { DataTable, type DataTableColumn, type DataTableProps } from "@crispy-seed/data-table";import { useState } from "react";interface Company { id: string; name: string; employees: number; revenue: number; updatedAt: string;}const day = 24 * 60 * 60 * 1000;const ago = (days: number) => new Date(Date.now() - days * day).toISOString();const rows: Company[] = [ { id: "stripe", name: "Stripe", employees: 8000, revenue: 16000000.5, updatedAt: ago(1) }, { id: "figma", name: "Figma", employees: 1300, revenue: 600000.25, updatedAt: ago(3) }, { id: "linear", name: "Linear", employees: 60, revenue: 30000.75, updatedAt: ago(14) }, { id: "vercel", name: "Vercel", employees: 500, revenue: 100000.1, updatedAt: ago(40) },];const columns: DataTableColumn<Company>[] = [ { key: "name", header: "Company" }, { key: "employees", header: "Employees", type: "number" }, { key: "revenue", header: "Revenue", type: "number" }, { key: "updatedAt", header: "Updated", type: "date" },];export default function DataTableFormatting() { // Open a number or date column's menu and pick "Formatting". The chosen formats are // reported to `onColumnFormatsChange`; seed them with `defaultColumnFormats`. const [formats, setFormats] = useState<NonNullable<DataTableProps<Company>["columnFormats"]>>({}); return ( <div style={{ width: "100%", maxWidth: 760, padding: 24 }}> <DataTable columns={columns} data={rows} columnMenu defaultColumnFormats={{ revenue: { decimals: 2 }, updatedAt: { dateDisplay: "relative" }, }} onColumnFormatsChange={setFormats} /> <pre style={{ margin: "12px 0 0", fontSize: 12 }}> {Object.keys(formats).length ? JSON.stringify(formats) : "No format changed yet."} </pre> </div> );}
defaultColumnFormats / columnFormats + onColumnFormatsChange: a map of column key to { grouping, decimals, dateDisplay }
loading replaces the entire body with a spinner + loadingLabel (taking priority over error/empty state). error takes next priority and replaces the entire body. If no rows exist after search/filter (or from the start), it shows empty (default "No results.").
Providing onLoadMore automatically calls it when a sentinel row near the bottom of the scroll container enters view (no manual pagination UI). If it returns a Promise, loadingMore automatically turns on during that time; when hasMore becomes false, the sentinel row disappears and is no longer triggered. You can layer style (e.g., maxHeight) and other properties on the scroll container itself via scrollProps.
"use client";import { DataTable, type DataTableColumn } from "@crispy-seed/data-table";import { useState } from "react";interface Row { id: string; name: string;}const PAGE_SIZE = 10;const TOTAL = 40;const allRows: Row[] = Array.from({ length: TOTAL }, (_, i) => ({ id: String(i), name: `Record ${i + 1}`,}));const columns: DataTableColumn<Row>[] = [{ key: "name", header: "Name" }];// `onLoadMore` fires when a sentinel row near the bottom of the scroll container// enters view (IntersectionObserver-driven -- there's no manual pagination UI).// Returning a Promise turns on `loadingMore` automatically until it resolves.export default function DataTableInfiniteScroll() { const [shown, setShown] = useState(PAGE_SIZE); const onLoadMore = () => new Promise<void>((resolve) => { setTimeout(() => { setShown((count) => Math.min(count + PAGE_SIZE, TOTAL)); resolve(); }, 500); }); return ( <div style={{ width: "100%", maxWidth: 480, padding: 24 }}> <DataTable columns={columns} data={allRows.slice(0, shown)} onLoadMore={onLoadMore} hasMore={shown < TOTAL} scrollProps={{ style: { maxHeight: 280 } }} /> </div> );}
On an entity column, hoverCard returns the contents of a card shown when the name is hovered, onOpenRecord makes the name itself a link-style button, and onOpenPreview adds a hover icon that opens a side preview. Pair the preview with RecordPreview. The three are independent: a column can use any combination.
DataTableViewsControl in toolbarActions lets users save and switch between views. Lift column order, hidden columns, widths, pins, toolbar sorts and toolbar filters into controlled state, then pass captureState (read the current state) and applyState (restore a saved one). storageKey persists the views in local storage.
When the toolbar sort or filter differs from the active view, an unsaved-changes bar appears with Discard changes, Save for everyone and Save as new view. Column layout changes (order, hidden, widths, pins) do not mark the view as changed. The views menu also has a Filter views search, Duplicate, and Add to favorites (favorites are listed first).
DataTable renders as actual <table>/<thead>/<tbody>/<tfoot>/<tr>/<th scope="col">/<td> (not a div grid with ARIA roles from the past) -- column alignment of header/body/footer is structurally guaranteed by a single <colgroup>, and native table semantics that screen readers expect are preserved. Selection checkboxes can have their accessibility names specified via selectAllLabel/getRowSelectionLabel, and the search field can have its accessibility name specified via searchLabel.