View as Markdown

Pivot Table

Appearance and templates

The whitelisted display props, renderCell, renderHeader, getCellClassName and renderTooltip, a hyperlink recipe with onCellClick, and cell selection with its events.

Display props

PivotTable renders through the Data Grid renderer but does not pass its settings through. A whitelist of display props is forwarded:

Prop Default
rowHeight the Data Grid default
columnWidth 120
rowHeaderWidth 220 (compact), 150 per column (tabular)
height 400
resizable, reorderable off
textWrap off
overflow the Data Grid default
gridLines 'both'
striped, highlightOnHover off, Data Grid default
emptyCellText ''

Subtotal and grand total rows carry salmon-pivot-table-subtotal-row and salmon-pivot-table-grand-total-row; colors come from the theme seeds. Number and date formats are model data (pivotModel.formats, Editors).

Templates

Prop Context
renderCell(ctx) { cell, rowHeader, columnHeader, selected, defaultContent }
renderHeader(ctx) { header, axis, defaultContent }
getCellClassName(ctx) as renderCell; returns a class string
renderTooltip(ctx) { cell, rowHeader, columnHeader }

cell is the engine's PivotCell: value, formattedValue, kind (value, subtotal, grandTotal), rowKey, columnKey, measure and rowCount. defaultContent is the formatted value (or emptyCellText), so a template can wrap it instead of formatting again:

const renderCell = ({ cell, defaultContent }: PivotCellContext) =>
  cell.value !== null && cell.value < 0 ? <span className="negative">{defaultContent}</span> : defaultContent;

<PivotTable pivot={pivot} renderCell={renderCell} />

Columns are rebuilt when a render prop changes identity, so define render props at module level or memoize them. Templates return React elements; no HTML strings are rendered. To change the value itself (not only its display) use getCellValue (Aggregation).

To show links, render a link in renderCell or renderHeader and handle the click in onCellClick:

const renderHeader = ({ header, axis, defaultContent }: PivotHeaderContext) =>
  axis === 'rows' && header.field === 'country' ? <a href={`/countries/${header.label}`}>{defaultContent}</a> : defaultContent;

<PivotTable
  pivot={pivot}
  renderHeader={renderHeader}
  onCellClick={(event) => {
    // event.cell is null on a row header; event.rowHeader is the row's member.
    if (event.cell && event.cell.value !== null && event.cell.value > 10_000) openDetails(event.rowKey, event.columnKey);
  }}
/>

Any condition (all cells, row or column headers, value cells, by value or by header text) is a branch in the render prop.

Selection

Cell selection is off by default:

<PivotTable
  data={data}
  defaultPivotModel={model}
  selection={{ multiple: true }}           // or `selection` for multiple cells, `{ multiple: false }` for one
  onBeforeSelectionChange={(event) => {}}  // preventDefault() cancels
  onSelectionChange={(event) => console.log(event.keys)}
/>

With a shared store (pivot={pivot}), pass onBeforeSelectionChange and onSelectionChange to usePivot() instead: the store fires them.

Ranges select as a box (drag, Shift+click, Shift+arrows). Selected cells are keyed rowKey|columnKey (event.cells holds { rowKey, columnKey } pairs) and stored in the pivot store (usePivotState(pivot, (s) => s.selection)), so they survive scrolling and re-renders.

HTML strings and class names

Salmon UI never renders HTML strings and React escapes text, so there is no HTML sanitizer option and no string templates, which would need a runtime compiler that breaks a strict CSP. Use renderCell, renderHeader, renderTooltip and renderLoading for custom content; toolbar items can render React content. Style the root with className.

Cell templates and conditional formats

Open demo

Custom value and header content, a hyperlink row header handled by onCellClick, class names per cell, tooltips, conditional format tones and box cell selection.

Region / Country
2024
2025
2026
Grand total
Americas
$4,135Americas · 2024: $4,135 (6 rows)
$5,681Americas · 2025: $5,681 (6 rows)
$4,427Americas · 2026: $4,427 (6 rows)
$14,243Americas · Grand Total: $14,243 (18 rows)
$2,308Brazil · 2024: $2,308 (3 rows)
$3,081Brazil · 2025: $3,081 (3 rows)
$2,454Brazil · 2026: $2,454 (3 rows)
$7,843Brazil · Grand Total: $7,843 (9 rows)
$1,827Canada · 2024: $1,827 (3 rows)
$2,600Canada · 2025: $2,600 (3 rows)
$1,973Canada · 2026: $1,973 (3 rows)
$6,400Canada · Grand Total: $6,400 (9 rows)
Asia
$5,183Asia · 2024: $5,183 (6 rows)
$5,329Asia · 2025: $5,329 (6 rows)
$5,475Asia · 2026: $5,475 (6 rows)
$15,987Asia · Grand Total: $15,987 (18 rows)
$2,351India · 2024: $2,351 (3 rows)
$3,124India · 2025: $3,124 (3 rows)
$2,497India · 2026: $2,497 (3 rows)
$7,972India · Grand Total: $7,972 (9 rows)
$2,832Japan · 2024: $2,832 (3 rows)
$2,205Japan · 2025: $2,205 (3 rows)
$2,978Japan · 2026: $2,978 (3 rows)
$8,015Japan · Grand Total: $8,015 (9 rows)
Europe
$6,059Europe · 2024: $6,059 (6 rows)
$4,805Europe · 2025: $4,805 (6 rows)
$4,951Europe · 2026: $4,951 (6 rows)
$15,815Europe · Grand Total: $15,815 (18 rows)
$3,270France · 2024: $3,270 (3 rows)
$2,643France · 2025: $2,643 (3 rows)
$2,016France · 2026: $2,016 (3 rows)
$7,929France · Grand Total: $7,929 (9 rows)
$2,789Germany · 2024: $2,789 (3 rows)
$2,162Germany · 2025: $2,162 (3 rows)
$2,935Germany · 2026: $2,935 (3 rows)
$7,886Germany · Grand Total: $7,886 (9 rows)
Grand total
$15,377Grand Total · 2024: $15,377 (18 rows)
$15,815Grand Total · 2025: $15,815 (18 rows)
$14,853Grand Total · 2026: $14,853 (18 rows)
$46,045Grand Total · Grand Total: $46,045 (54 rows)

Clicked: nothing yet · 0 cell(s) selected