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)
- 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 bynumberFormatter(). - 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.
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) (truealso when the contents are shorter than the visible height).atBottomin theonScrollargument is the same check.- The example starts
followRef(followin the Solid example) attrue, so it jumps to the end after the first render. To show from the top, start withfalse. Makerowsthe only dependency of the effect (adding other values jumps to the end even when no rows were added). - Don't decide with
sourceinonScroll. 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
rowsmatter. Put the array received inonRowsChangeback into state as is (rebuilding it with map loses the structural sharing of unchanged rows and discards the undo history). - In React, define
rowKeyGetteroutside the component or wrap it inuseCallback. 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 ifonChangesChangeoronActiveCellChangechanges 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: stickyelements 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, anddownloadCsvfor 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.