Detail rows (Master/Detail)
Open any UI (a sub-grid or a form) right below a row with detailRow
Pass the detailRow prop to "expand" each row and insert your own UI (a card) right below the master row (the equivalent of AG Grid's Master/Detail). Where row grouping is a feature in which "the library creates group rows", detail rows are the path where you decide entirely what goes below a row. The two are independent and can be used together.
Demo (orders > lines)
- Open and close with the toggle column (▸) at the start. Pressing ▸ doesn't move the active cell. With the keyboard, move the active cell to the toggle column and press
Enter/Space. ▸ is read as "Show details for row 3" (the same number as the row header; since 1.3.0; textsshowDetails/hideDetails). "Canceled" rows without lines can't be expanded, usingisExpandable. - The card contains a nested
SpreadsheetGridand a memo input. Arrow keys, clicks and right clicks in the card don't reach the outer grid. - "Open SO-2404" and "Close all" are the handle's
setDetailRowExpanded()/collapseAllDetailRows(), and the "Open:" display comes fromonExpandedDetailRowKeysChange. - Sorting from a column header or filtering by the Status column keeps the expanded state on the row keys.
Usage
<SpreadsheetGrid
rows={orders}
columns={columns}
rowKeyGetter={(row) => row.id}
detailRow={{
height: 230, // band height (px, fixed)
isExpandable: (row) => row.lines.length > 0, // whether each row can expand (all rows when omitted)
render: ({ row, collapse }) => (
<OrderDetailCard order={row} onClose={collapse} />
),
}}
onExpandedDetailRowKeysChange={(keys) => save(keys)}
/>The ctx passed to render is { row, rowKey, rowIndex, sourceRowIndex, collapse }. Calling collapse() closes that detail row.
Placing the toggle yourself (showToggleColumn: false)
You can also draw the toggle from any column's renderCell instead of using the dedicated toggle column. While detailRow is on, CellRenderContext has ctx.detail ({ expanded, expandable, toggle, setExpanded }).
const columns: GridColumn<Order>[] = [
{
key: 'customer',
title: 'Customer',
width: 200,
renderCell: ({ value, detail }) => (
<span style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
{detail?.expandable && (
<button type="button" onClick={detail.toggle}>
{detail.expanded ? '▾' : '▸'}
</button>
)}
{String(value)}
</span>
),
},
]
<SpreadsheetGrid detailRow={{ render, showToggleColumn: false }} ... />Key points of the behavior
-
The row order doesn't change — expanding doesn't add a third kind of row to the visible row list (view index). A full-width band is inserted right below the master row, and following rows just move down by the band's height. The scroll position doesn't move when expanding.
-
The card is sticky in the center pane — the card stays at the left edge of the viewport (right next to the left pinned pane) when scrolling horizontally. Its width is the visible width of the center pane.
-
Fixed height —
height(default200) is fixed, and contents that overflow scroll inside the card (auto height isn't supported). -
State is kept by row key — it follows the same row across sorting, filtering and adding or removing rows. Rows excluded by a filter show no band, and it comes back when they return. Removing an expanded row from
rowsdrops its key from the expanded keys and callsonExpandedDetailRowKeysChange(adding a row with the same key back keeps it closed; serverSide isn't covered). Keys restored withsetDetailRowExpanded()beforerowsloads stay until that row arrives. They aren't part ofgetState()or undo / redo, so persist them withonExpandedDetailRowKeysChange+setDetailRowExpanded(). -
Cards are mounted only while in the render window — they unmount when scrolled out and remount when they come back. Keep state you want to hold in the card (half-typed values and so on) on your side, keyed by
rowKey. -
Taborder —Tabfrom the last column goes into that row's card (its first input and so on), andTabfrom the card's last element leaves the grid (it doesn't pass through other rows' cards).Shift+Tabgoes in reverse (the card's first element → that row's last-column cell; coming back from after the grid lands on the last element of the active cell's row's card). Inside dialogs or popovers opened from the card through a portal,Tabkeeps the browser default (or their own focus trap). When a card closes while focus is inside it (collapse()/ the toggle /ctx.detail.setExpanded(false)/ the handle'ssetDetailRowExpanded(key, false)/collapseAllDetailRows()), that row's cell (in the active cell's column) becomes the active cell and focus returns to the table, scrolling it into view if it's outside the visible area (so focus doesn't vanish with the closed card). -
Event boundary — keyboard, clipboard, right click, double click and drag starts inside the card don't reach the grid. While focus is inside the card, focus restoration after committing an edit or closing a popover doesn't steal focus. Even with another
SpreadsheetGridnested in the card, the outer grid's auto-height measuring and column header lookups don't target the inner cells. -
Writing back to the parent row from a nested grid — when reflecting edits in the card's grid to the outer
rows, replacing them directly with the parent'ssetRowsmakes the outer grid treat it as an outside replacement and clear its undo history. To keep the outer history, pass it with the outer handle'sapplyRows(next)(it's added to the outer history, and the outerCtrl/Cmd+Zcan undo that write-back too). When the outer grid uses change tracking (trackChanges), pass it withapplyRows(next)too (passing it withsetRowsmakes it an outside replacement, so values edited in the card aren't counted as unsaved and don't appear ingetChanges()). The same goes for editing rows with your own form in the card. The inner grid's undo history is cleared after a write-back, since the innerrowsget replaced from outside (use the outerCtrl/Cmd+Zto undo).const outerRef = useRef<SpreadsheetGridHandle<Task>>(null); // in onRowsChange of the grid in the card, write back to the outer row const writeSubtasks = (taskId: string, subtasks: Subtask[]) => outerRef.current?.applyRows(tasks.map((t) => (t.id === taskId ? { ...t, subtasks } : t))); -
Selection — bands aren't cells, so they aren't targets of selection or the active cell. The highlight of a range spanning a band is drawn in parts that avoid the band.
-
serverSide (
dataSource) — works, but when the query (filters / sorting / global filter) changes, everything closes (the result set is replaced entirely, and keys of unloaded rows can't be scanned). Bands of unloaded rows aren't shown. -
Limit — when
rows × rowHeight + the total of open bandsexceeds 15,000,000px (about 410,000 rows at 36px; 8,000,000px = about 220,000 rows in Firefox), bands aren't drawn (development warning; the expanded state is kept, and they show once you narrow the rows). While the rows alone exceed this limit, the toggle (▸) isn't shown either, andEnter/Spacedon't open or close (ctx.detail.expandableisfalsetoo; since 1.0.1). -
With row grouping — only leaf rows can expand; group rows can't.
-
Nothing changes without
detailRow— no toggle column is inserted,ctx.detailisundefined, and the handle's detail row API does nothing.
For the imperative API for opening and closing (setDetailRowExpanded / getExpandedDetailRowKeys / collapseAllDetailRows), see the API reference; for every field of DetailRowOptions, see props.