SpreadsheetGrid
Guides

Custom rendering

Draw cells, headers, top / bottom bars, editors and the context menu freely with React / Solid components

The grid's look and behavior can be replaced with ordinary React components (Solid components in the Solid version). Everything follows the style "pass a function and get a context", and the grid holds the state.

Custom cells (renderCell)

Pass a renderer to column.renderCell to draw cell contents freely. Besides value / row, the context has setValue, which writes directly to that cell, so you can build interactive cells such as buttons and toggles.

Rows 5 of 5Columns 4 of 4Sort: —
#
1
2
3
4
5
Rows 5 of 5Columns 4 of 4
Cell —Range —0 cells / 0 rows0 columns
{
  key: 'status', title: 'Status', width: 120,
  renderCell: ({ value }) => (
    <span className={badgeClass(value)}>{String(value)}</span>
  ),
},
{
  key: 'stock', title: 'Stock', width: 160,
  renderCell: ({ value, setValue }) => (
    <>
      <button onClick={() => setValue(Number(value) - 1)}>−</button>
      <span>{Number(value)}</span>
      <button onClick={() => setValue(Number(value) + 1)}>+</button>
    </>
  ),
}
  • All fields of the context are in CellRenderContext<T> (row / rowIndex / sourceRowIndex / rowKey / colIndex / value / column / isActive / isSelected / isEditing / readOnly / setValue).
  • renderCell replaces the display. Editing (the editor on double click) is still handled by editor, and they work together (the Status column in the demo = badge display + select editor).
  • To change only the displayed text, use the lighter valueFormatter. For conditional coloring only, cellClassName is the lightest.

Cell notes (cellNote)

Cells for which column.cellNote returns a string get a mark (triangle) in the top right, and hovering shows that string in a tooltip. It's the equivalent of FarPoint SPREAD's cell notes and Excel's notes, and shows "this cell has extra information" without renderCell. Try it with the cellNote toggle in the playground.

{
  key: 'partNo', title: 'Part no.', width: 140,
  cellNote: ({ row }) =>
    [row.isNew && 'Added in this import.', row.otherUses > 0 && `Also used in ${row.otherUses} other places`]
      .filter(Boolean)
      .join('\n'),  // \n breaks the line. An empty string shows no mark
}
  • The mark's color can be changed with the token --ssg-note-indicator. In cells that also have an input error (validate), the error's small red triangle overlaps the note's triangle so both are visible, and the tooltip reads "error → line break → note".
  • Background colors and so on are still added with cellClassName (notes are only the mark and the tooltip).
  • Notes aren't included in CSV, copy or export. For details, see the API reference.

Custom headers (renderHeader)

column.renderHeader replaces the label part of a column header (the "📋 Task" column in the demo above). Header features such as sorting, the menu and resizing stay as they are.

{
  key: 'name', title: 'Task', width: 180,
  renderHeader: ({ column }) => (
    <span>📋 {column.title}</span>
  ),
}

Pressing buttons or inputs placed inside doesn't start a column range selection (the button's onClick is called, and the input gets focus). In columns narrower than 120px, hovering the header shows the sort grip and the column menu's ⋮ overlapping it, but they hide while the pointer is over a button and so on inside, so you can press it as is (since 1.3.0).

Header alignment (headerAlign)

Column header text follows the column's align unless you set it (headers of numeric columns with align: 'right' go right too, and 'center' goes center). For columns where only the header should differ, set headerAlign.

Hover a header to see the grip and ⋮
Rows 7 of 7Columns 5 of 5Sort: —
#
1
2
3
4
5
6
7
Rows 7 of 7Columns 5 of 5
Cell —Range —0 cells / 0 rows0 columns
const columns = [
  { key: 'name', title: 'Item', width: 180 },
  { key: 'amount', title: 'Amount', width: 130, align: 'right' },                   // header right too
  { key: 'status', title: 'Status', width: 90, align: 'center' },                   // header centered too
  { key: 'code', title: 'Code', width: 100, align: 'right', headerAlign: 'left' },  // only the header left
];
  • Right-aligned headers mirror their layout. The sort arrow and the filter mark go right to the left of the label, and the grip and ⋮ shown on hover go to the left of those, so the text's right edge lines up with the numbers in the cells and the header isn't hidden while hovering.
  • In headers 120px wide or more, the grip and ⋮ shown on hover sit between the label and the arrow / mark (left of the arrow / mark when right-aligned) and don't hide the arrow and mark. A long label shrinks with "…" while hovering (since 1.0.2; up to 1.0.1, the controls overlapped the header edge and hid the arrow and mark).
  • In headers narrower than 120px, there's no room for the text and ⋮ side by side, so while hovering the controls overlap the header edge (the left edge when right-aligned), hiding the text, arrow and mark there. Pressing the header edge (where ⋮ is while hovering) opens the column menu. On touch devices (devices without hover) the controls are always shown, so headers narrower than 120px show only ⋮ overlapping (if there is one), without the grip (since 1.0.2).
  • Centered headers center only the text; the arrow, mark and controls go on the right, as in left-aligned columns. With the arrow or mark shown, the text is centered within the width excluding them.
  • It applies to renderHeader contents too (the label container's text-align). The header width measured by column auto-sizing is the same regardless of alignment.
  • To add styles in CSS, use .ssg-header-cell--align-right / .ssg-header-cell--align-center (up to 0.62.0 headers were always left-aligned and these classes didn't exist).

Top bar / bottom bar (renderTopBar / renderBottomBar)

renderTopBar / renderBottomBar replace a bar entirely with your own component. The SpreadsheetGridSlotContext passed in has reading and writing the global filter (globalFilterText / setGlobalFilterText), rows / filteredRows, the selection state, and derivedSummary, a formatted derived summary, so you can write a practical bar without importing helpers.

🍀 My inventory6 / 6 rows
#
1
2
3
4
5
6
Rows 6 of 6Filter: —0 cells / 0 rowsSelect a range of numbers to see the sum / average
<SpreadsheetGrid
  renderTopBar={(ctx) => (
    <div className="my-toolbar">
      <input
        value={ctx.globalFilterText}
        onChange={(e) => ctx.setGlobalFilterText(e.target.value)}
        placeholder="Search"
      />
      <span>{ctx.filteredRows.length} / {ctx.rows.length} rows</span>
    </div>
  )}
  renderBottomBar={(ctx) => (
    <div className="my-statusbar">
      <span>{ctx.derivedSummary.rowSummaryText}</span>
      <span>{ctx.derivedSummary.selectionStatsText}</span>
    </div>
  )}
  ...
/>
  • derivedSummary holds summary strings for rows, columns, filters and sorting, the number of selected cells and so on (SpreadsheetGridDerivedSummary).
  • With 2 or more cells selected, selectionAggregates holds the selection aggregates (average / count / sum / min / max) (GridSelectionAggregates). The default bottom bar shows average / count / sum on the right (in the free space next to the cell / range) (hide it with showSelectionAggregates={false}; details in the API reference).
  • In the Solid version, read ctx values inside JSX (reading them in the function body or by destructuring the argument rebuilds the bar every time the value changes, losing the input's focus and half-typed text).
  • In the React version, avoid passing ctx or rows / filteredRows as is to child component props (<MyBar ctx={ctx} /> / <MyBar rows={ctx.filteredRows} />), and pass only the values you use (for counts, ctx.filteredRows.length or derivedSummary). Development builds of React 19.2 and later walk large arrays to diff props, so with around 1 million rows one sort can take tens of seconds (production builds aren't affected). Reading ctx directly in the bar, as in the example above, is fine.
  • To change only the default bars' texts ("Rows 120 of 120", "Cell B3" and so on), use localeText without building a bar (for English, see English and text; for the list of keys, see the API reference). The derivedSummary strings are built from the same texts.
  • To adjust without replacing the whole bar, use the display props: showTopBar / showBottomBar (master switches), and per part of the default bars, showTopBarSummary / showTopBarFilter / showFilterChipBar and so on. For the list, see the API reference.

Custom editors (type: 'custom')

When the built-in editors (text / number / select / date / checkbox) aren't enough, you can draw the editing UI itself. ctx.commit(value) commits and ctx.cancel() cancels. Committing a non-string bypasses the parser and writes the domain value as is.

Rows 4 of 4Columns 3 of 3Sort: —
#
1
2
3
4
Rows 4 of 4Columns 3 of 3
Cell —Range —0 cells / 0 rows0 columns
{
  key: 'rating', title: 'Rating', width: 180, editable: true,
  renderCell: ({ value }) => <Stars n={Number(value)} />,
  editor: {
    type: 'custom',
    render: (ctx) => (
      <StarPicker
        value={Number(ctx.value)}
        onPick={(n) => ctx.commit(n)}   // write the number as is
        onCancel={() => ctx.cancel()}
      />
    ),
  },
}
  • Focus management and key bindings are your responsibility (ctx also has row / initialText and so on; initialText is the key typed when editing started by typing a character, and the cell value's text String(value ?? '') when opened by double click / Enter / F2).
  • When you show your own popup inside the editor (a list of candidates and so on), put it inside the dialog that contains the grid, not in document.body (anchor.closest('dialog') ?? document.body). Inside a modal <dialog>, elements directly under body are hidden behind it and can't be pressed (Use it inside a dialog).

Context menu (right click)

With enableContextMenu + getContextMenuItems, you can define the right-click menu for cells and the row number gutter. It's a fully custom design in which the library has no default items at all, and returning an empty array falls through to the browser's standard menu.

Rows 4 of 4Columns 2 of 2Sort: —
#
1
2
3
4
Rows 4 of 4Columns 2 of 2
Cell —Range —0 cells / 0 rows0 columns

Right-click a cell or a row number

<SpreadsheetGrid
  enableContextMenu
  getContextMenuItems={({ target, isTargetSelected }) => {
    if (target.type !== 'cell' && target.type !== 'rowHeader') return [];
    return [
      { kind: 'label', label: 'Row actions' },
      { label: 'Duplicate row', onSelect: () => duplicate(target.row) },
      { kind: 'separator' },
      { label: 'Delete row', danger: true, onSelect: () => remove(target.row) },
    ];
  }}
  ...
/>

Items are a discriminated union (action / label / separator / custom), and custom is an escape hatch for free drawing. For details, see the API reference.

Which to choose

What you wantHow
Formatting the displayed text (thousands separators and so on)valueFormatter
Conditional colors and backgroundscellClassName + CSS
A note on a cell (top-right mark + tooltip)cellNote
Your own UI in cells (badges / bars / buttons)renderCell
Replacing the editing UI itselfeditor: { type: 'custom' }
Decorating header labelsrenderHeader
Toggling parts of the barsthe showTopBar* / showBottomBar* props
Building a bar from scratchrenderTopBar / renderBottomBar
A right-click menugetContextMenuItems
Adjusting color and size tokens at onceTheming and styling

On this page