SpreadsheetGrid
Guides

Large data and pinned columns

Virtualizing 100,000 rows and 3-pane pinned columns (pinned)

The grid virtualizes both rows and columns, and only the visible area + overscan becomes DOM. The client-side row model handles about 1 million rows.

Demo (100,000 rows)

100,000 rows (generated in the browser)
Rows 100000 of 100000Columns 8 of 8Sort: —
#
ID
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
Status
Discontinued
Active
Active
Paused
Discontinued
Active
Discontinued
Paused
Discontinued
Paused
Discontinued
Discontinued
Paused
Active
Active
Discontinued
Paused
Discontinued
Paused
Active
Discontinued
Rows 100000 of 100000Columns 8 of 8
Cell —Range —0 cells / 0 rows0 columns
  • The ID column is pinned left and the Status column right (pinned: 'left' | 'right'). They stay in place when you scroll horizontally.
  • The "To row 50,000" button calls the handle's scrollToRow(49999, { align: 'center' }).
  • The Stock value column is a computed column with getValue (quantity × unit price), shown with thousands separators by numberFormatter().
  • Filters, sorting and the global filter work on 100,000 rows as is.

Pinning columns

const columns: GridColumn<Row>[] = [
  { key: 'id', title: 'ID', width: 90, pinned: 'left' },
  // ...center scrolling columns...
  { key: 'status', title: 'Status', width: 100, pinned: 'right' },
]

The layout has 3 panes, left / center / right (sticky based), and pinned columns are always visible. scrollToCell doesn't scroll horizontally for pinned columns.

While the total of pinned columns (including the row number column) is wider than the grid and can't leave 120px for the center (phone widths and so on), pinning is dropped on screen only, starting from the innermost right pinned columns and then the innermost left pinned columns, so they scroll in the center. pinned in columns doesn't change, and they go back to pinned when the grid gets wider.

Following the end of a growing table

In tables whose rows keep growing, like logs or events, to keep showing added rows only while at the end, check whether you're at the end with the handle's isAtBottom() before adding rows, and if you were, call scrollToBottom() after adding (since 1.2.0). It doesn't chase while the user has scrolled up to read.

Following the bottom
Rows 30 of 30Columns 6 of 6Sort: —
#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Rows 30 of 30Columns 6 of 6
Cell —Range —0 cells / 0 rows0 columns
const gridRef = useRef<SpreadsheetGridHandle<LogRow>>(null);
const followRef = useRef(true);
const [following, setFollowing] = useState(true);

const append = (incoming: LogRow[]) => {
  // before adding, remember whether we're at the end.
  followRef.current = gridRef.current?.isAtBottom() ?? true;
  setRows((prev) => [...prev, ...incoming]);
};

// go to the end after the added rows are drawn.
useEffect(() => {
  if (followRef.current) {
    gridRef.current?.scrollToBottom();
  }
}, [rows]);

<SpreadsheetGrid
  ref={gridRef}
  rows={rows}
  columns={columns}
  // used for the "following the end" display (false when someone scrolls up).
  onScroll={({ atBottom }) => setFollowing(atBottom ?? false)}
/>
  • isAtBottom() returns whether vertical scrolling is at the end (the bottom edge) (true also when the contents are shorter than the visible height). atBottom in the onScroll argument is the same check.
  • The example starts followRef (follow in the Solid example) at true, so it jumps to the end after the first render. To show from the top, start with false. Make rows the only dependency of the effect (adding other values jumps to the end even when no rows were added).
  • Don't decide with source in onScroll. When the table shrinks by filtering or re-measuring row heights, the position the browser pulls in also arrives as 'user'. Conversely, in tables that map the scroll position to a shrunk range ("Things to watch with large data" below), when rows are added while scrolled up to read, the position adjustment that keeps the viewed rows arrives as 'api'.

Things to watch with large data

  • Stable references of rows matter. Put the array received in onRowsChange back into state as is (rebuilding it with map loses the structural sharing of unchanged rows and discards the undo history).
  • In React, define rowKeyGetter outside the component or wrap it in useCallback. With an inline function (rowKeyGetter={(row) => row.id}), every time the parent re-renders, the row order and the aggregates that use it (conditional formatting min / max and so on) are rebuilt over all rows. With 1 million rows, one re-render takes about 50–100ms, and if onChangesChange or onActiveCellChange changes the parent's state, it happens on every such operation. In Solid, functions in props aren't recreated, so it's fine as is.
  • Editing one cell or adding rows at the end while sorted doesn't re-sort every row. Only rows whose sort column value changed and added rows are reinserted at their new positions, and edits unrelated to the sort column keep the order as is (column filters also reuse the previous result when the filtered result doesn't change). When the sort column of many rows (more than 1,024) changes at once, when many are added, or when rows are added somewhere other than the end, it sorts everything.
  • When the logical total height (number of rows × row height) exceeds 15,000,000px (about 410,000 rows at 36px), the scroll position is mapped to a shrunk range to fit within the browser's maximum element height. Only Firefox shrinks from 8,000,000px (about 220,000 rows at 36px) (Firefox doesn't keep position: sticky elements such as the column header row in place beyond about 8.95 million px). Adding or removing rows keeps the rows you're viewing in place (since 1.0.1). In this range, detail rows (detailRow) aren't drawn and the toggle isn't shown.
  • The global text filter automatically switches to time-sliced application beyond 50,000 rows, and doesn't block the main thread while you type (the grid shows a built-in overlay while applying).
  • On the other hand, sorting every row, applying column filters (including relative dateSet presets) and CSV output (downloadCsv / exportCsv) aren't time-sliced. With 1 million rows, sorting a string column or the "Today" preset freezes the screen for about 1–2 seconds, and downloadCsv for about 5 seconds (no progress is shown; our measurement). If you use these often at this scale, consider showing "Exporting…" yourself before exporting, or leaving sorting and filtering to the server with the server-side row model (SSRM).
  • Variable row heights (autoHeight) add measuring cost, so fixed row heights are recommended for very large data.
  • When the data is on a server, the server-side row model (SSRM) fetches only the blocks near the visible area and keeps memory bounded.

On this page