React

Data Table

A component that displays data in rows and columns as a table and supports sorting, selection, search, filter, inline editing, and infinite scroll.

Available now

DataTable ships in @crispy-seed/data-table, now published at version 0.15.0. The API on this page is stable.

Coming in the next release

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

Usage

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).

interface Company {
  id: string;
  name: string;
  arr: number;
}

const columns: DataTableColumn<Company>[] = [
  { key: "name", header: "Company" },
  { key: "arr", header: "ARR", type: "currency", sortable: true },
];

<DataTable columns={columns} data={rows} />;

Props

DataTable

Prop

Type

columnsDataTableColumn<TRow>[]
dataTRow[]

DataTableColumn

Prop

Type

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.

typeDisplay
text (default)plain string
entityseed Avatar(20px) + weight-500 name. If onOpenPreview is provided, a "preview" icon appears on hover and focus
url / emaillink style, no underline normally, underline only on hover
tagsone or more pills with consistently hashed color per value
statussingle-value colored pill
numberright-aligned, tabular-nums
currencyright-aligned, tabular-nums, symbol (default "$") prefixed
date / datetimelocale formatted with locale (default "en-US")
ratingmaxRating filled/empty stars (default 5)
checkboxread-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 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).

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.

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").

  • 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.

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.

  • 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".

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.

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.

  • 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.

  • 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.").

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.

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.

  • 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).

  • DataTableViewsControl: storageKey, captureState, applyState
  • Controlled pairs: columnOrder, hiddenColumnKeys, columnWidths, pinnedColumnKeys, toolbarSorts, toolbarFilters (each with its on...Change)

Accessibility

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.

Table of contents