Data grid / foldkit-data-grid
Virtualization
A grid draws only what its scroll container shows. The container's scroll
offsets and size are the fact; GridViewport keeps them in the Model, and
VirtualGrid.window turns them into the rows and columns to draw.
ts
import { VirtualGrid } from 'foldkit-data-grid'
const shown = VirtualGrid.window({
projection: grid,
rowHeight: 32,
width: column => (column === 'sku' ? 120 : 80),
viewport: { top: 0, left: 0, width: 600, height: 320 },
overscan: { rows: 4, columns: 1 },
})
// shown.rows: { start: 0, end: 2, before: 0, after: 0 }: draw rows [start, end)
// shown.start, shown.centerColumns, shown.end: the columns to draw, in order
// shown.width, shown.height: the size of the scrollable contentVirtualGrid.window(options)is pure. Rows are one fixed height, so the row window is arithmetic on the scroll offset and never walks the rows; the center columns are found by binary search over their widths. Pinned columns are always drawn, outside the horizontal window.beforeandafterare the space the undrawn rows and columns take, for spacers.headerHeightleaves header rows inside the container out of the body. It throws for a row height that is not a positive number.Grid.window({ rows, state, rowHeight, headerHeight, overscan })is that window for a placed grid, asfoldkit-mixins-data-grid's view works it out from the same input: to say how many rows are drawn, read it here rather than estimating.VirtualGrid.reveal(options)is the least scroll that shows a cell, as{ top, left }, or none when it is already in view. A pinned column never scrolls, so only its row is brought in.- The grid's
revealhelper asks for that scroll from outside the view, as a "go to row" control does:Placed.helpers.reveal(rows, { row, column, rowHeight, headerHeight })is a Step of the application, folded in its ownupdatelike any helper (Bundle.helpersOf(Grid.bundle).reveal(model.grid, rows, target)on the grid's Model alone).rowcounts from zero inrowsas they are now;columnis optional, and without it the sideways scroll stays where it is. It moves no focus, and does nothing for a row in view or one thatrowsdoes not have.rowHeightandheaderHeightare the ones the view is given. GridViewport.bundleholds{ top, left, width, height }.GridViewport.Measureis a Mount for the scroll container: it reports the geometry when it mounts and on every scroll and resize. Readings that are not numbers are ignored, and an overscroll reads as the edge.GridViewport.scrollTo(viewportId, offsets)is the Command that applies a reveal: it scrolls the container and reportsRevealed, so the next window is drawn from the new offsets without waiting for the scroll event.
See the 100,000-row benchmarks for timings at 100,000 rows.