SpreadsheetGrid
Guides

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: none
Rows 6 of 6Columns 6 of 6Sort: —
#
Details
Order no.
1
SO-2401
2
SO-2402
3
SO-2403
4
SO-2404
5
SO-2405
6
SO-2406
Rows 6 of 6Columns 6 of 6
Cell —Range —0 cells / 0 rows0 columns
  • 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; texts showDetails / hideDetails). "Canceled" rows without lines can't be expanded, using isExpandable.
  • The card contains a nested SpreadsheetGrid and 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 from onExpandedDetailRowKeysChange.
  • 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 (default 200) 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 rows drops its key from the expanded keys and calls onExpandedDetailRowKeysChange (adding a row with the same key back keeps it closed; serverSide isn't covered). Keys restored with setDetailRowExpanded() before rows loads stay until that row arrives. They aren't part of getState() or undo / redo, so persist them with onExpandedDetailRowKeysChange + 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.

  • Tab order — Tab from the last column goes into that row's card (its first input and so on), and Tab from the card's last element leaves the grid (it doesn't pass through other rows' cards). Shift+Tab goes 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, Tab keeps 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's setDetailRowExpanded(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 SpreadsheetGrid nested 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's setRows makes 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's applyRows(next) (it's added to the outer history, and the outer Ctrl/Cmd+Z can undo that write-back too). When the outer grid uses change tracking (trackChanges), pass it with applyRows(next) too (passing it with setRows makes it an outside replacement, so values edited in the card aren't counted as unsaved and don't appear in getChanges()). 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 inner rows get replaced from outside (use the outer Ctrl/Cmd+Z to 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 bands exceeds 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, and Enter / Space don't open or close (ctx.detail.expandable is false too; 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.detail is undefined, 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.

On this page