# Data Table URL: /react/components/data-table Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/data-table.mdx A component that displays data in rows and columns as a table and supports sorting, selection, search, filter, inline editing, and infinite scroll. DataTable ships in `@crispy-seed/data-table`, now published at version 0.15.0. The API on this page is stable. These features are on the main development branch but not in the published 0.15.0 yet: - `columnManager` (Add column button) and the header glyphs (`enriched` bolt, read-only pencil) - The "Copying 1 cell..." notice, Enter opening the record, and disabled Paste / Clear value on read-only cells - The drag handle on toolbar sort rows and the Today / Tomorrow / Next week date quick picks - The drop indicator line while dragging a column header - The unsaved view bar, Filter views search, Duplicate, and Add to favorites in saved views ## Preview ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; import { useState } from "react"; interface Company { id: string; company: { name: string; avatar?: string }; domain: string; categories: string[]; stage: string; employees: number; arr: number; rating: number; } const rows: Company[] = [ { id: "stripe", company: { name: "Stripe", avatar: "https://www.google.com/s2/favicons?domain=stripe.com&sz=64" }, domain: "stripe.com", categories: ["Payments", "Fintech"], stage: "Series I", employees: 8000, arr: 16_000_000_000, rating: 5, }, { id: "figma", company: { name: "Figma", avatar: "https://www.google.com/s2/favicons?domain=figma.com&sz=64" }, domain: "figma.com", categories: ["Design", "SaaS"], stage: "Series E", employees: 1300, arr: 600_000_000, rating: 4, }, { id: "linear", company: { name: "Linear", avatar: "https://www.google.com/s2/favicons?domain=linear.app&sz=64" }, domain: "linear.app", categories: ["Dev tools"], stage: "Series B", employees: 60, arr: 30_000_000, rating: 4, }, { id: "vercel", company: { name: "Vercel", avatar: "https://www.google.com/s2/favicons?domain=vercel.com&sz=64" }, domain: "vercel.com", categories: ["Dev tools", "Cloud"], stage: "Series E", employees: 500, arr: 100_000_000, rating: 3, }, ]; // `value(row)` is the single accessor sort/search/filter/export share -- an `entity` // column's raw field is `{ name, avatar }`, so sorting needs this to read the // comparable name rather than stringifying the whole object. const columns: DataTableColumn[] = [ { key: "company", header: "Company", type: "entity", sortable: true, value: (row) => row.company.name }, { key: "domain", header: "Domain", type: "url" }, { key: "categories", header: "Categories", type: "tags" }, { key: "stage", header: "Stage", type: "status", sortable: true }, { key: "employees", header: "Employees", type: "number", sortable: true }, { key: "arr", header: "ARR", type: "currency", sortable: true }, { key: "rating", header: "Rating", type: "rating" }, ]; export default function DataTablePreview() { const [selectedIds, setSelectedIds] = useState(["stripe"]); return (
); } ``` ## Usage ```tsx import { DataTable, type DataTableColumn } from "@seed-design/react"; ``` 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[]`, and rows are passed as `data: TRow[]`. `TRow` must have `id: string` (selection/sorting/editing identify rows by this `id`). ```tsx interface Company { id: string; name: string; arr: number; } const columns: DataTableColumn[] = [ { key: "name", header: "Company" }, { key: "arr", header: "ARR", type: "currency", sortable: true }, ]; ; ``` ## Props ### `DataTable` ### `DataTableColumn` ## Cell types 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`). ## Sorting 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](#toolbar-search-sort-filter) below, those take priority over header click sorting. ## Examples ### Selection 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). ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; import { useState } from "react"; interface Row { id: string; name: string; } const rows: Row[] = [ { id: "1", name: "Ann Lee" }, { id: "2", name: "Bo Park" }, { id: "3", name: "Cy Kim" }, ]; const columns: DataTableColumn[] = [{ key: "name", header: "Name" }]; export default function DataTableSelection() { const [selectedIds, setSelectedIds] = useState([]); return (

{selectedIds.length === 0 ? "No rows selected" : `${selectedIds.length} row(s) selected`}

`Select ${row.name}`} />
); } ``` ### Toolbar: search, sort, filter 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. ```tsx "use client"; import { DataTable, type DataTableColumn, type ToolbarFilter, type ToolbarSort } from "@seed-design/react"; import { useState } from "react"; interface Company { id: string; company: { name: string; avatar?: string }; stage: string; employees: number; } const rows: Company[] = [ { id: "google", company: { name: "Google" }, stage: "Public", employees: 182_000 }, { id: "stripe", company: { name: "Stripe" }, stage: "Series I", employees: 8_000 }, { id: "figma", company: { name: "Figma" }, stage: "Series E", employees: 1_300 }, { id: "notion", company: { name: "Notion" }, stage: "Series C", employees: 800 }, { id: "linear", company: { name: "Linear" }, stage: "Series B", employees: 60 }, { id: "vercel", company: { name: "Vercel" }, stage: "Series E", employees: 500 }, ]; const stages = Array.from(new Set(rows.map((row) => row.stage))); // `searchable` on Company opts it into the toolbar's free-text search box. // `kind: "select"` + `filterValues` gives Stage the closed-vocabulary "is any of" // checkbox picker instead of the free-text condition set; `kind: "number"` swaps // Employees to "less than / greater than". const columns: DataTableColumn[] = [ { key: "company", header: "Company", type: "entity", value: (row) => row.company.name, searchable: true }, { key: "stage", header: "Stage", type: "status", kind: "select", filterValues: stages, sortable: true }, { key: "employees", header: "Employees", type: "number", kind: "number", sortable: true }, ]; export default function DataTableToolbar() { const [query, setQuery] = useState(""); const [toolbarSorts, setToolbarSorts] = useState([{ key: "stage", dir: "asc" }]); const [toolbarFilters, setToolbarFilters] = useState([ { id: "f1", key: "employees", op: "greaterthan", value: "300" }, ]); return (
); } ``` ### Advanced filters 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"`). ```tsx "use client"; import { DataTable, type DataTableColumn, type ToolbarFilter } from "@seed-design/react"; import { useState } from "react"; interface Company { id: string; name: string; stage: string; employees: number; } const rows: Company[] = [ { id: "stripe", name: "Stripe", stage: "Series I", employees: 8000 }, { id: "figma", name: "Figma", stage: "Series E", employees: 1300 }, { id: "notion", name: "Notion", stage: "Series C", employees: 800 }, { id: "linear", name: "Linear", stage: "Series B", employees: 60 }, { id: "vercel", name: "Vercel", stage: "Series E", employees: 500 }, ]; const columns: DataTableColumn[] = [ { key: "name", header: "Company" }, { key: "stage", header: "Stage", type: "status" }, { key: "employees", header: "Employees", type: "number", kind: "number", sortable: true }, ]; export default function DataTableAdvancedFilter() { // `connective` joins a row to the one above it (absent = "and"). This reads: // stage is "Series E" OR employees greater than 5000. const [toolbarFilters, setToolbarFilters] = useState([ { id: "f1", key: "stage", op: "is", value: "Series E" }, { id: "f2", key: "employees", op: "greaterthan", value: "5000", connective: "or" }, ]); return (
); } ``` - `advancedToolbarFilter` / `defaultAdvancedToolbarFilter` / `onAdvancedToolbarFilterChange`: open state of the editor - `ToolbarFilter.connective`: `"and"` | `"or"`, how a row joins the one above it ### Inline editing 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. ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; import { useCallback, useState } from "react"; interface Task { id: string; title: string; status: string; urgent: boolean; assigneeId: string; } const ASSIGNEES = [ { value: "ann", label: "Ann Lee" }, { value: "bo", label: "Bo Park" }, { value: "cy", label: "Cy Kim" }, ]; const initialRows: Task[] = [ { id: "1", title: "Ship DataTable docs", status: "In progress", urgent: true, assigneeId: "ann" }, { id: "2", title: "Review PR #1063", status: "Todo", urgent: false, assigneeId: "bo" }, { id: "3", title: "Cut 2.6.0 release", status: "Todo", urgent: false, assigneeId: "cy" }, ]; const STATUSES = ["Todo", "In progress", "Done"]; // Plain `editable` columns (no `editor`) open a double-click text/number/date input; // `editor: "select"`/`"switch"` are always-live (no double-click, the widget commits // immediately). Typing "fail" into a text/number editor rejects the commit on purpose, // below, so the revert-and-show-an-error path is reachable by hand. const columns: DataTableColumn[] = [ { key: "title", header: "Title", editable: true, searchable: true }, { key: "status", header: "Status", type: "status", editable: true, editor: "select", options: STATUSES.map((s) => ({ value: s, label: s })) }, { key: "urgent", header: "Urgent", type: "checkbox", editable: true, editor: "switch" }, { key: "assigneeId", header: "Assignee", editable: true, editor: "reference", refOptions: ASSIGNEES }, ]; export default function DataTableEditing() { const [rows, setRows] = useState(initialRows); const onEdit = useCallback( (id: string, key: string, value: string) => new Promise((resolve, reject) => { setTimeout(() => { if (value.trim().toLowerCase() === "fail") { reject(new Error("Could not save -- try again")); return; } setRows((current) => current.map((row) => row.id === id ? { ...row, [key]: key === "urgent" ? value === "true" : value } : row, ), ); resolve(); }, 400); }), [], ); return (
); } ``` ### Keyboard, clipboard and context menu 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. ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; 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[] = [ { 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 (

{log}

setRows((prev) => prev.map((row) => (row.id === id ? { ...row, [key]: value } : row))) } onViewEditHistory={(row, columnKey) => setLog(`Edit history requested: ${row.id} / ${columnKey}`) } />
); } ``` - `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 ### Summary row (ColumnCalc) 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". ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; 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[] = [ { 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 (
); } ``` ### Column menu, resize & sticky columns `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. ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; 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[] = [ { 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 (
); } ``` ### Add column and hidden columns `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`. ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; import { useState } from "react"; interface Company { id: string; name: string; stage: string; employees: number; location: string; ceo: string; founded: string; } const initialRows: Company[] = [ { id: "stripe", name: "Stripe", stage: "Series I", employees: 8000, location: "South San Francisco", ceo: "Patrick Collison", founded: "2010-09-01", }, { id: "figma", name: "Figma", stage: "Series E", employees: 1300, location: "San Francisco", ceo: "Dylan Field", founded: "2012-01-01", }, { id: "linear", name: "Linear", stage: "Series B", employees: 60, location: "San Francisco", ceo: "Karri Saarinen", founded: "2019-01-01", }, { id: "vercel", name: "Vercel", stage: "Series E", employees: 500, location: "San Francisco", ceo: "Guillermo Rauch", founded: "2015-01-01", }, ]; // `enriched` adds the bolt glyph (a string becomes its tooltip). With `onEdit` on the // table, `editable: false` adds the read-only pencil glyph to that header. const columns: DataTableColumn[] = [ { key: "name", header: "Company", editable: true }, { key: "stage", header: "Stage", type: "status", editable: true }, { key: "employees", header: "Employees", type: "number", enriched: "Synced from LinkedIn." }, { key: "location", header: "Location", enriched: true, editable: false }, { key: "ceo", header: "CEO", editable: true }, { key: "founded", header: "Founded", type: "date", editable: false }, ]; export default function DataTableColumnsManager() { const [rows, setRows] = useState(initialRows); return (
setRows((prev) => prev.map((row) => (row.id === id ? { ...row, [key]: value } : row))) } />
); } ``` - `columnManager`: show the Add column button - `defaultHiddenColumnKeys` / `hiddenColumnKeys` + `onHiddenColumnKeysChange`: hidden columns - `DataTableColumn.enriched`: `true` or a tooltip string - `DataTableColumn.editable: false` together with `onEdit`: read-only pencil glyph ### Per-column formatting 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. ```tsx "use client"; import { DataTable, type DataTableColumn, type DataTableProps } from "@seed-design/react"; 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[] = [ { 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["columnFormats"]>>({}); return (
        {Object.keys(formats).length ? JSON.stringify(formats) : "No format changed yet."}
      
); } ``` - `defaultColumnFormats` / `columnFormats` + `onColumnFormatsChange`: a map of column key to `{ grouping, decimals, dateDisplay }` ### Loading, error & empty states `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."`). ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; import { useState } from "react"; interface Row { id: string; name: string; } const rows: Row[] = [ { id: "1", name: "Ann Lee" }, { id: "2", name: "Bo Park" }, ]; const columns: DataTableColumn[] = [{ key: "name", header: "Name" }]; const MODES = ["data", "loading", "error", "empty"] as const; // `loading` replaces the whole body (spinner + `loadingLabel`) and wins over // `error`/empty; `error` replaces the body next; an empty `data` array (with // neither flag set) falls through to the `empty` slot. export default function DataTableStates() { const [mode, setMode] = useState<(typeof MODES)[number]>("loading"); return (
{MODES.map((m) => ( ))}
); } ``` ### Infinite scroll 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`. ```tsx "use client"; import { DataTable, type DataTableColumn } from "@seed-design/react"; 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[] = [{ 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((resolve) => { setTimeout(() => { setShown((count) => Math.min(count + PAGE_SIZE, TOTAL)); resolve(); }, 500); }); return (
); } ``` ### Record hover card and preview 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. ```tsx "use client"; import { DataTable, type DataTableColumn, RecordPreview } from "@seed-design/react"; import { useMemo, useState } from "react"; interface Company { id: string; company: { name: string; avatar?: string }; stage: string; employees: number; } const rows: Company[] = [ { id: "stripe", company: { name: "Stripe", avatar: "https://www.google.com/s2/favicons?domain=stripe.com&sz=64", }, stage: "Series I", employees: 8000, }, { id: "figma", company: { name: "Figma", avatar: "https://www.google.com/s2/favicons?domain=figma.com&sz=64" }, stage: "Series E", employees: 1300, }, { id: "linear", company: { name: "Linear", avatar: "https://www.google.com/s2/favicons?domain=linear.app&sz=64", }, stage: "Series B", employees: 60, }, ]; export default function DataTableHoverCard() { const [previewRow, setPreviewRow] = useState(null); const [opened, setOpened] = useState(null); const columns = useMemo[]>( () => [ { key: "company", header: "Company", type: "entity", value: (row) => row.company.name, // Hover the name for a card; click the name to open the record; use the // hover icon to open the side preview. hoverCard: (row) => (
{row.company.name}
{row.stage} · {row.employees.toLocaleString("en-US")} people
), onOpenRecord: (row) => setOpened(row.company.name), onOpenPreview: (row) => setPreviewRow(row), }, { key: "stage", header: "Stage", type: "status" }, { key: "employees", header: "Employees", type: "number" }, ], [], ); return (
{opened &&

Opened record: {opened}

} setPreviewRow(null)} avatar={previewRow?.company.avatar} highlights={ previewRow ? [ { key: "stage", label: "Stage", value: previewRow.stage }, { key: "employees", label: "Employees", value: previewRow.employees.toLocaleString("en-US"), }, ] : undefined } />
); } ``` - `hoverCard(row)`: render prop for the card contents; you own the card styling - `onOpenRecord(row)`: called when the name is clicked, or on Enter on the primary cell - `onOpenPreview(row)` and `openPreviewLabel`: preview icon and its accessible label ### Saved views `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). ```tsx "use client"; import { DataTable, type DataTableColumn, DataTableViewsControl, type DataTableViewState, type ToolbarFilter, type ToolbarSort, } from "@seed-design/react"; import { useCallback, useState } from "react"; interface Company { id: string; name: string; stage: string; employees: number; location: string; } const rows: Company[] = [ { id: "stripe", name: "Stripe", stage: "Series I", employees: 8000, location: "South San Francisco", }, { id: "figma", name: "Figma", stage: "Series E", employees: 1300, location: "San Francisco" }, { id: "notion", name: "Notion", stage: "Series C", employees: 800, location: "San Francisco" }, { id: "linear", name: "Linear", stage: "Series B", employees: 60, location: "San Francisco" }, { id: "vercel", name: "Vercel", stage: "Series E", employees: 500, location: "San Francisco" }, ]; const columns: DataTableColumn[] = [ { key: "name", header: "Company", searchable: true, sortable: true }, { key: "stage", header: "Stage", type: "status", sortable: true }, { key: "employees", header: "Employees", type: "number", kind: "number", sortable: true }, { key: "location", header: "Location" }, ]; export default function DataTableSavedViews() { const [columnOrder, setColumnOrder] = useState(columns.map((c) => c.key)); const [hiddenColumnKeys, setHiddenColumnKeys] = useState([]); const [columnWidths, setColumnWidths] = useState>({}); const [pinnedColumnKeys, setPinnedColumnKeys] = useState([]); const [toolbarSorts, setToolbarSorts] = useState([]); const [toolbarFilters, setToolbarFilters] = useState([]); // Read the live table state when the user saves a view... const captureState = useCallback( (): DataTableViewState => ({ columnOrder, hiddenColumnKeys, columnWidths, pinnedColumnKeys, toolbarSorts, toolbarFilters, }), [columnOrder, hiddenColumnKeys, columnWidths, pinnedColumnKeys, toolbarSorts, toolbarFilters], ); // ...and write a saved view back onto it when the user picks one. const applyState = useCallback((state: DataTableViewState) => { if (state.columnOrder) setColumnOrder(state.columnOrder); if (state.hiddenColumnKeys) setHiddenColumnKeys(state.hiddenColumnKeys); if (state.columnWidths) setColumnWidths(state.columnWidths); if (state.pinnedColumnKeys) setPinnedColumnKeys(state.pinnedColumnKeys); if (state.toolbarSorts) setToolbarSorts(state.toolbarSorts); if (state.toolbarFilters) setToolbarFilters(state.toolbarFilters); }, []); return (
} />
); } ``` - `DataTableViewsControl`: `storageKey`, `captureState`, `applyState` - Controlled pairs: `columnOrder`, `hiddenColumnKeys`, `columnWidths`, `pinnedColumnKeys`, `toolbarSorts`, `toolbarFilters` (each with its `on...Change`) ## Accessibility DataTable renders as actual ``/``/``/``/``/``, 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`.
`/`` (not a `div` grid with ARIA roles from the past) -- column alignment of header/body/footer is structurally guaranteed by a single `