Sizing (height)
Set the grid's height with height / maxHeight. Fit it in the parent with '100%'
The grid's height is set with two props, height and maxHeight. With neither, the scroll area is the height of its contents, and scrolls beyond 480px.
height values and what they mean
What height sets the height of depends on the kind of value.
height value | Height of what | Result |
|---|---|---|
A string containing % ('100%' / '50%' / 'calc(100% - 40px)') | The whole grid, including the top bar, the filter chip bar, the scroll area and the bottom bar | The grid fits in its parent. Bars keep their own height and the rest becomes the scroll area |
number (px), a string without % ('400px' / '50vh' / 'calc(100vh - 120px)') | The scroll area only | The whole grid is taller by the bars (height={400} → about 473px with the default bars) |
| Not set | — | The scroll area is the height of its contents, clipped at maxHeight (default 480px) |
Demo (height="100%")
- Changing the parent's height keeps the whole grid (bars included) inside the dashed box.
- Turning the bars off widens the scroll area by that much.
- There are 1,000 rows, but only the visible rows are rendered (virtualization).
Common patterns
Filling a parent with a fixed height
<div style={{ height: 600 }}>
<SpreadsheetGrid rows={rows} columns={columns} height="100%" />
</div>Filling the rest of a flex column (below a page header and so on)
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
<header>…</header>
<div style={{ flex: 1, minHeight: 0 }}>
<SpreadsheetGrid rows={rows} columns={columns} height="100%" />
</div>
</div>Give the flex: 1 child minHeight: 0 ('min-height': 0 in Solid's style). Without it, the child grows to the height of its contents (all rows).
Placing side by side (next to a sidebar and so on)
<div style={{ display: 'flex', height: '100vh' }}>
<nav style={{ width: 240 }}>…</nav>
<main style={{ flex: 1, minWidth: 0 }}>
<SpreadsheetGrid rows={rows} columns={columns} height="100%" />
</main>
</div>When placing side by side, give the flex child holding the grid (the same for a CSS grid child) minWidth: 0. Flex and grid children don't get narrower than their contents by default, so without it the child widens to the width of every column, the whole page overflows horizontally, and the grid's horizontal scrolling doesn't work.
A fixed height for the scroll area
<SpreadsheetGrid rows={rows} columns={columns} height={400} />A number is the height of the scroll area. The whole grid is taller by the bars.
maxHeight (the scroll area's maximum)
maxHeight is always the maximum of the scroll area regardless of the kind of height (bars not included).
| Combination | Scroll area height |
|---|---|
maxHeight only | The height of the contents, at most maxHeight |
height={400} maxHeight={300} | min(400, 300) = 300px |
height="100%" maxHeight={300} | min(300, parent height − bars). With a large parent, the whole grid shrinks to bars + 300px |
Rules for % and common mistakes
- The parent element must have a definite height (a fixed
height,100vh, a sized flex child withminHeight: 0, and so on). If the parent's height isauto,%resolves toauto. Then the grid grows to the height of all rows, and row virtualization stops working (every row is rendered). This is a general CSS rule, so the library can't solve it. - Set the height with the
heightprop.style={{ height }}or aclassNameon the root alone don't set the scroll area's height (the default480pxmaximum stays, and the bars may be cut off). - Strings without
%, like'50vh'/'calc(100vh - 120px)', are the scroll area's height relative to the viewport and so on, not the parent. To fit the whole grid in the viewport, put a wrapper with height100vhand useheight="100%"inside it.
Placing it inside zoom (transform: scale())
Even inside an ancestor's transform: scale(), clicks, drag range selection, the fill handle, column width dragging and row / column drag auto-scrolling work at the position under the pointer (since 1.0.1; the scale is computed from the ratio of the table's visual size to its layout size).
Checking it works (verifying in the DOM)
In tests and automated checks, checking these points catches setup mistakes.
- With
%, the root element (.ssg-root) has thessg-root--fill-heightclass. - When there are more rows than fit,
.ssg-scroll-containerhasscrollHeight > clientHeight(it can scroll). - The number of rendered rows (
.ssg-body-row) is about the number of visible rows, not the total. If every row is rendered, the parent's height isn't definite. - The height of
.ssg-rootdoesn't exceed the parent's height.
jsdom doesn't compute layout, so check actual sizes in a real browser (Playwright and so on).