SpreadsheetGrid
Guides

Range decorations

Draw a box and a name tag on a range decided by row and column keys with rangeDecorations. Marks for ranges in review, places someone else is editing, or what AI changed

Pass ranges to rangeDecorations to draw a colored box and a name tag on them (since 1.13.0). Ranges are decided by row and column keys, so they stay on the same cells after sorting, filtering and reordering columns. They're display only and aren't involved in selection, editing, copy or export. Use them as marks for ranges in review, places someone else is editing, or what AI or an import changed.

<SpreadsheetGrid
  rows={rows}
  columns={columns}
  rowKeyGetter={(row) => row.id} // required, since ranges are decided by row keys
  rangeDecorations={[
    { id: 'review', rowKeys: [6, 7, 8], columnKeys: ['q2', 'q3'], label: 'In review', color: '#d97706', fill: true },
    { id: 'sato', rowKeys: [cursorRow], columnKeys: ['q1'], label: 'Sato', color: '#2563eb' },
  ]}
/>

Demo (budget > in review, needs approval, someone else's place)

Rows 20 of 20Columns 6 of 6Sort: —
#
Dept
1
Sales
2
Sales
3
Sales
4
Sales
5
Sales
6
Engineering
7
Engineering
8
Engineering
9
Engineering
10
Engineering
11
Admin
12
Admin
13
Admin
14
Admin
15
Admin
16
Production
17
Production
18
Production
19
Production
20
Production
Rows 20 of 20Columns 6 of 6
Cell —Range —0 cells / 0 rows0 columns

Sort by a column header: boxes on rows that move apart split, and rows next to each other share one box. The boxes ignore the pointer, so you can select and edit the cells under them.

Options (GridRangeDecoration)

FieldDefaultContents
id—The decoration's identifier. When the range of the same id changes, the box slides to the new place. Use a different value per decoration (2 or more with the same id give one development warning)
rowKeys—Row keys of the range (rowKeyGetter values; without rowKeyGetter they're compared with the row position = the index in rows, with one development warning)
columnKeys—Column keys of the range
color--ssg-range-decoration (the accent color by default)The color of the box and the name tag background (a CSS color). The name tag text color is white or a dark color, whichever is readable on this color (for #rrggbb / #rgb / rgb(); white for other forms)
labelNoneThe name tag text. Omit for a box only
labelColorAs aboveThe name tag text color (when you decide it yourself)
fillfalsetrue fills the range lightly
lineStyle'solid''dashed' for a dashed line

A range is rowKeys crossed with columnKeys. Rows and columns don't need to be in display order, and rows or columns apart from each other are fine.

To mark scattered cells (cells changed by an import and so on), combining them into one decoration per column, rather than one per cell, reduces the count (put the keys of the rows changed in that column into rowKeys).

// one per column: { qty: [3, 8], price: [3, 5] } → 2 decorations
const decorations = Object.entries(changedRowsByColumn).map(([columnKey, rowKeys]) => ({
  id: `import-${columnKey}`,
  rowKeys,
  columnKeys: [columnKey],
  color: '#7c3aed',
}));

How they're drawn

  • Boxes: rows and columns next to each other on screen are combined into one box. Rows separated by sorting and columns with another column between them get separate boxes, and the name tag goes only on the first box.
  • Pinned columns: ranges spanning the left or right pinned columns are drawn per pane, with no line at the boundary (the same as the selection). They're also split around detail row bands.
  • Name tags: always shown on the first visible box. They straddle the box's top line, on the side that doesn't hide text in the row above (left if the range's leftmost column is numeric, right if both ends are text, left from text to numbers; a little inside the box's corner). For ranges on the top row, or cut right below the column headers, they go inside the box. When the top of the range is hidden by scrolling, they move down inside the top visible row. Long name tags are cut at 220px with "…". In tables with tight rows (density="compact"), name tags are smaller too.
    • Name tags may slightly overlap marks in the top left / top right of the range's first cell (the change triangle and so on) or chips in the row above. Name tags of 2 decorations at the same place overlap; in that case, leave one name tag out.
  • Where they aren't drawn: rows removed by filtering, rows inside closed groups or trees, hidden columns, and rows not loaded yet (server-side). Label rows, group rows, the total row, pinned rows and the entry row aren't targets. Rows and columns whose keys aren't in the current table are skipped.
  • Stacking: boxes go above cells and below the selection and active cell outlines. They don't take the pointer, so you can press cells through a box. Decorations stack in the order passed.
  • Motion: when the range of a decoration with the same id changes, the box slides. Vertical sliding happens only in tables where rows slide too (where animateRows is in effect); in tables with animateRows off, autoHeight or server-side, it moves right away like the rows. It doesn't slide while you drag a column width. It doesn't slide with motion="off" or the OS "reduce motion" setting (Motion).

Screen readers

Boxes and name tags aren't read (aria-hidden). Instead, when a cell inside a range becomes active, the name tag is added to that cell's description (aria-description). When it overlaps error, note or unsaved descriptions, the order is "error → note → unsaved → name tag". Decorations without a name tag aren't read.

Count and speed

  • Up to about 200 don't affect rendering speed. Over 1,000 give one development warning (combine adjacent ranges into one).
  • Changing decorations doesn't redraw rows or cells (only the box layer is redrawn). Even if a new array is built on every render, nothing happens when the contents are the same (no need to wrap it in useMemo).

Changing the look

TargetName
Box.ssg-range-decoration (id in data-ssg-range-decoration). Fill is .ssg-range-decoration--fill, dashed is .ssg-range-decoration--dashed
Name tag.ssg-range-decoration-label
Default colorsTokens --ssg-range-decoration (the box and name tag background of decorations without color) / --ssg-range-decoration-contrast (the name tag text of decorations without color)
/* slightly larger name tags */
.ssg-range-decoration-label {
  font-size: 12px;
}

In Windows high contrast (forced-colors), boxes and name tags are drawn in the system highlight color.

Using it with /lite

With /lite, add rangeDecorationsFeature (it isn't in standardFeatures). Passing rangeDecorations without it draws nothing, with one development warning.

import { createSpreadsheetGrid, rangeDecorationsFeature } from '@ishibashi0112/spreadsheet-grid/lite';

const Grid = createSpreadsheetGrid({ features: { rangeDecorations: rangeDecorationsFeature } });

On this page