Data grid
A virtualized spreadsheet grid with range selection, inline editing, fill handle, grouping with subtotals, .xlsx export, and selection-to-chart recommendations.
import { DataGrid } from '@uthereal/ui/data-grid'Data grid playground
| Product | Category | Q1 | Q2 | Q3 | Margin | Launch |
|---|---|---|---|---|---|---|
| Oak lounge chair | Furniture | $64,000 | $78,500 | $91,200 | 42.5% | Jan 15, 2026 |
| Arc floor lamp | Lighting | $52,000 | $61,000 | $74,800 | 48.0% | Feb 1, 2026 |
| Handwoven wool rug | Textiles | $48,000 | $53,400 | $62,900 | 36.2% | Feb 18, 2026 |
| Walnut writing desk | Furniture | $71,500 | $84,200 | $96,400 | 39.8% | Mar 4, 2026 |
| Brass wall sconce | Lighting | $31,200 | $38,900 | $44,600 | 51.4% | Mar 22, 2026 |
| Washed linen throw | Textiles | $24,800 | $29,100 | $33,500 | 46.1% | Apr 10, 2026 |
| Glass pendant | Lighting | $39,400 | $45,800 | $54,200 | 44.7% | Apr 28, 2026 |
| Cedar entryway bench | Furniture | $29,600 | $35,200 | $41,900 | 41.0% | May 12, 2026 |
Overview
A data grid displays and edits structured tabular datasets in place like a spreadsheet. Readers select rectangular cell ranges, edit text, numbers, select options, or dates inline, drag the fill handle to extend numeric or date series, copy and paste with Excel or Google Sheets, sort across multiple columns, filter by column syntax, group rows with subtotals, and export CSV or .xlsx workbooks.
When two or more cells are selected, the status bar runs the deterministic recommendCharts() engine on the selection and surfaces a ranked chart switcher. Hosts can render live chart previews inside the popover via renderChartPreview and handle chart insertion through onVisualize or visualizeAction.
Use DataGrid when readers edit many cells in place, analyze multi-column financial or operational data, or jump directly from tabular selections to charts. For read-only record lists without spreadsheet editing, use a simpler table layout. For single-record editing, use form inputs.
Usage
import { useState } from 'react'
import {
DataGrid,
type DataGridColumnInput,
type DataGridRow,
} from '@uthereal/ui/data-grid'
const columns: DataGridColumnInput[] = [
{ id: 'item', label: 'Item', width: 180, pinned: true },
{
id: 'status',
label: 'Status',
type: 'select',
options: ['Planned', 'Active', 'Done'],
},
{ id: 'q1', label: 'Q1', type: 'currency' },
{ id: 'q2', label: 'Q2', type: 'currency' },
{
id: 'margin',
label: 'Margin',
type: 'percent',
decimals: 1,
editable: false,
},
{ id: 'target', label: 'Target', type: 'date' },
]
export function BudgetGrid() {
const [rows, setRows] = useState<DataGridRow[]>([
{
id: 'r1',
item: 'Design systems',
status: 'Active',
q1: 42000,
q2: 48500,
margin: 34.5,
target: '2026-03-31',
},
{
id: 'r2',
item: 'Cloud hosting',
status: 'Planned',
q1: 18400,
q2: 21000,
margin: 22.0,
target: '2026-06-30',
},
])
return (
<DataGrid
label="Operating budget"
columns={columns}
rows={rows}
onRowsChange={setRows}
exportFormats={['csv', 'xlsx']}
/>
)
}Every column needs a unique id matching the keys on each row, and every row needs a stable unique id. Store raw numbers for number, currency, and percent columns (34.5 renders as 34.5%) and ISO calendar days (YYYY-MM-DD) for date columns.
Examples
Grouping and subtotals
Pass column ids in groupBy to nest rows into an expandable treegrid. Each group header shows its item count and computes subtotals using each column's aggregate. Exporting .xlsx writes outlined group rows with native Excel SUBTOTAL formulas so grand totals never double-count subtotals.
| Line item | Department | Q1 | Q2 | Efficiency |
|---|---|---|---|---|
| Cloud compute | Engineering | $48,200 | $52,400 | 78.4% |
| CI runners | Engineering | $14,600 | $16,200 | 84.1% |
| Design tooling | Design | $9,400 | $9,800 | 91.2% |
| User research | Design | $12,800 | $15,400 | 86.5% |
| Compliance audit | Operations | $22,000 | $19,500 | 74.0% |
| Support desk | Operations | $17,500 | $18,900 | 88.3% |
Inline editing and bulk actions
Combine select, date, currency, and read-only (editable: false) columns with bulkActions and exportFormats: ['csv', 'xlsx']. Double-click a cell or press Enter to edit, drag the corner fill handle to continue numeric or date runs, and check rows in the gutter to reveal bulk actions.
| Milestone | Status | Budget | Complete | Target date | Owner |
|---|---|---|---|---|---|
| Schema v2 | Done | $24,000 | 100% | Jan 31, 2026 | Core |
| Streaming API | Active | $38,500 | 72% | Feb 28, 2026 | Platform |
| Audit exports | Active | $19,200 | 45% | Mar 31, 2026 | Security |
| Regional failover | Planned | $44,000 | 10% | Apr 30, 2026 | Infra |
Behavior
Column types
| Type | Alignment | Parsing & editing | Default aggregate |
|---|---|---|---|
text | Start | Plain text input; accent-insensitive substring, =exact, !exclude | none |
number | End | Parses commas, spaces, minus, accounting (12); range 10..50 | sum |
currency | End | Formats with $ or column.currency ISO code; parses $ on paste | sum |
percent | End | Stores human percentages (32.5 → 32.5%); parses % on paste | average |
select | Start | Combobox listbox matching options case-insensitively; checklist filter | none |
date | Start | ISO day (YYYY-MM-DD) in UTC; DateInput calendar popover; 2026-01..2026-03 | none |
Selection-to-chart engine (recommendCharts)
Selecting two or more cells runs recommendCharts() on the deferred range (never mid-drag) and ranks up to six compatible @uthereal/ui chart types across all 20 shipped chart components.
| Export | Purpose |
|---|---|
recommendCharts | Profiles selected columns and returns ranked ChartRecommendation[] with lazy buildProps() |
inferColumnProfile | Infers numeric, temporal, categorical, percentage, currency, and geographic column metadata |
renderChartPreview | React slot receiving the active ChartRecommendation to mount a live chart inside the popover |
onVisualize | Fires with (recommendation, range) when the reader confirms "Insert chart" |
visualizeAction | Named host action dispatched through onAction(action, 'data-grid') on confirmation |
Virtualization, clipboard, and remote blocks
Both rows (overscan 6) and scrolling columns (overscan 240 px) are virtualized while pinned columns, the active cell, and the active editor stay mounted. Sorting reorders the view once so editing values never causes rows to jump under the cursor. Undo and redo retain up to 100 row snapshots.
For server-sized datasets, supply getRows (and optional blockSize, default 100): the grid loads blocks covering the viewport on scroll, caches up to 40 blocks, and resets the cache whenever sort, filters, or search change.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Data" | Accessible name for the grid. It also names the exported CSV file. |
columns | DataGridColumn[]Default: [{"id":"name","label":"Name","type":"text","pinned":true},{"id":"amount","label":"Amount","type":"currency"},{"id":"date","label":"Date","type":"date"}] | Column definitions in definition order, each with a unique id; pinned columns are drawn first. Up to 100. |
rows | DataGridRow[]Default: [] | Starting rows when uncontrolled, each with a unique id. Up to 10,000. |
maxHeight | integerDefault: 400 | Tallest the scrolling area grows before it scrolls, in px (160–4000). |
sort | DataGridSort[]Default: [] | Starting sort keys in priority order. Header clicks and the header menu report changes through onSortChange. |
filters | DataGridFiltersDefault: {} | Starting column filters keyed by column id. Text and number columns take a query string; select columns take the values to keep. |
selectedRowIds | string[]Default: [] | Starting checked row ids in data order. |
hiddenColumns | string[]Default: [] | Starting hidden column ids; defaults to the columns that set hidden. |
pinnedColumns | string[]Default: [] | Starting pinned column ids; defaults to the columns that set pinned, or the first column. |
density | DataGridDensityDefault: "standard" | Row height: compact 32, standard 40, comfortable 48 px. |
groupBy | string[]Default: [] | Group-by column ids, outermost first. Each group row shows a toggle, its value and row count, and a subtotal. |
rowSelection | booleanDefault: true | Shows the row gutter with row numbers and checkboxes. |
rowNumbers | booleanDefault: true | Shows the row number in the gutter. |
selectionStats | booleanDefault: true | Shows the active cell address and the Count, Sum and Average of the selected cells in the status bar. |
toolbar | booleanDefault: true | Shows the toolbar with search, undo and redo, filters, columns, density and export. |
totals | booleanDefault: true | Shows the sticky totals row; it covers every row the filters keep. |
visualize | booleanDefault: true | Shows the selection-to-chart action in the status bar when selected cells can be charted. |
visualizeAction | string— | Host-registered action sent when the reader confirms a chart recommendation, e.g. insert_chart. |
exportFormats | ("csv" | "xlsx")[]Default: ["csv"] | Formats Export offers. With more than one, Export opens a menu. xlsx keeps number formats, column widths, a frozen header, bold totals and groups as outlined rows with SUBTOTAL formulas. |
exportFileName | string— | Export file name without the extension. Defaults to a slug of label. |
canDeleteRows | booleanDefault: true | Shows Delete for checked rows. Deleting can be undone. |
bulkActions | DataGridBulkAction[]Default: [] | Extra toolbar actions for checked rows, shown between Export and Delete, each with a unique id. |
loading | booleanDefault: false | Shows placeholder rows and sets aria-busy. |
emptyLabel | stringDefault: "No rows yet" | Shown when there are no rows at all. |
searchLabel | stringDefault: "Search" | Accessible name of the quick search field. |
locale | string— | BCP 47 locale for formats. Omit it to inherit the page locale. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | DataGridTheme— | Color mode, accent, and tokens. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Group and status-bar animation preset. System reduced-motion preferences take precedence. |
motionOptions | DataGridMotionOptions— | Group open/close and status-bar transitions: a tween (ms) or a spring. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
onRowsChange | Fires with the full row array after edits, fills, pastes, cuts, clears, deletes, undo, redo |
onSortChange, onFiltersChange | Controlled callbacks for multi-column sort and column filter maps |
onSelectedRowIdsChange, onHiddenColumnsChange, onPinnedColumnsChange, onDensityChange, onGroupByChange | Controlled callbacks for grid view state |
defaultRows, defaultSort, defaultFilters, defaultSelectedRowIds, defaultHiddenColumns, defaultPinnedColumns, defaultDensity, defaultGroupBy | Uncontrolled initial values |
getRows, blockSize | Host-owned remote block loader (request) => Promise<DataGridRowsResult> |
renderChartPreview | Renders a live chart preview for the active ChartRecommendation inside the status popover |
onVisualize | Fires with (recommendation, range) when the reader confirms a recommended chart |
onAction | Host action handler (action, itemId?) for visualizeAction and bulkActions |
preset, tokens | Application defaults and --ui-* CSS variable overrides |
ref, className, style | Forwarded to the root grid container |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Arrow keys | Move active cell (inline axis mirrors automatically in dir="rtl") |
Shift + Arrow | Extend rectangular selection range from anchor |
Cmd/Ctrl + Arrow | Jump to grid edge (+ Shift extends range) |
Home, End | Move to first or last column (Cmd/Ctrl jumps to first or last grid cell) |
PageUp, PageDown | Move by one visible page of rows |
Cmd/Ctrl + A | Select all cells |
Ctrl + Space / Shift + Space | Extend selection to full columns / toggle row checks across selected rows |
Enter, F2 / any character | Edit active cell keeping value / start editing replacing value |
Enter, Tab (editing) | Commit edit and move down/up (Shift+Enter) or end/start (Shift+Tab) |
Escape | Cancel edit, collapse selection range to active cell, or clear checked rows |
Delete, Backspace | Clear editable cells in range (read-only cells skipped) |
Cmd/Ctrl + D | Fill down from top row of selection |
Cmd/Ctrl + C, X, V | Copy, cut, or paste TSV and HTML tables (tiles whole multiples) |
Cmd/Ctrl + Z, Shift+Z / Y | Undo or redo up to 100 steps |
Alt + ArrowLeft / ArrowRight | Narrow or widen focused header column by 16 px |
The grid renders role="grid" (or role="treegrid" when groupBy is active) with aria-multiselectable, aria-rowcount, aria-colcount, aria-rowindex, aria-colindex, aria-sort, and aria-busy. Group rows expose aria-level and aria-expanded; totals and subtotals carry full spoken labels. A polite role="status" region announces edits, sorts, copies, pastes, fills, deletes, and undo/redo, while a visually hidden native <table> provides a static screen-reader overview. Under forced-colors: active, selection fills and active borders map to system Highlight colors.
Motion and theming
Toolbar swaps, the filter row glide, and status bar notifications animate through LazyMotion and resolveDataGridMotion. motionOptions.groupDuration and motionOptions.statusDuration accept durations in milliseconds, and motionOptions.selection accepts a tween or spring. Under prefers-reduced-motion: reduce, travel, press scale, error shake, and skeleton pulse disable in favor of 120 ms opacity fades; motion="none" makes every transition immediate (0 ms).
| Token | CSS variable | Default | Purpose |
|---|---|---|---|
rowHeight | --ui-data-grid-row-height | 40px | Standard row height |
rowHeightCompact | --ui-data-grid-row-height-compact | 32px | Compact density row height |
rowHeightComfortable | --ui-data-grid-row-height-comfortable | 48px | Comfortable density row height |
headerHeight | --ui-data-grid-header-height | 40px | Sticky column header height |
gutter | --ui-data-grid-gutter | 48px | Row number and checkbox gutter |
cellPad | --ui-data-grid-cell-pad | 12px | Cell inline padding |
cellText / cellTextMono | --ui-data-grid-cell-text / -mono | 13px / 12px | Body and numeric cell type scale |
frameRadius | --ui-data-grid-frame-radius | 16px | Outer grid frame corner radius |
focusWidth | --ui-data-grid-focus-width | 2px | Active cell inset border width |
theme also accepts global mode, accent, surface, border, control, and popup tokens. An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, DataGrid is a leaf component. Declare visualizeAction and bulkActions[].action with registered snake_case host actions; the grid reports them via onAction(action, itemId). See Building with agents.
{
"type": "DataGrid",
"props": {
"label": "Q4 pipeline",
"visualizeAction": "insert_chart",
"columns": [
{ "id": "account", "label": "Account", "type": "text", "pinned": true },
{
"id": "stage",
"label": "Stage",
"type": "select",
"options": ["Qualified", "Proposal", "Closed"]
},
{ "id": "value", "label": "Value", "type": "currency" }
],
"rows": [
{
"id": "r1",
"account": "Northwind",
"stage": "Proposal",
"value": 84000
},
{ "id": "r2", "account": "Fabrikam", "stage": "Closed", "value": 62000 }
]
},
"children": []
}