WarUI

Row virtualization with fixed row height

GRID-A06-F01P0baselineShippedexperimental

Render only the rows that intersect the viewport, plus a small buffer, with a spacer that sizes the scrollbar to the full row count.

Live example

Expected behavior

The rendered row count stays near the viewport rows plus overscan whatever the row count. The scrollbar reflects the full dataset. Turning virtualization off renders every row, capped at 5,000 with a warning.

Source

const virtualizer = createRowVirtualizer({
  rowCount: 100_000,
  rowHeight: 32,
  viewportHeight: scroller.clientHeight,
  onRenderedRangeChange: render,
});
spacer.style.height = virtualizer.getTotalHeight() + 'px';
scroller.addEventListener('scroll', () => virtualizer.setScrollTop(scroller.scrollTop));
const { start, end } = virtualizer.getRenderedRowRange();

API reference

GRID-A06-F01 API
KindNameTypeDescription
OptionrowVirtualization—Render only visible rows. Defaults to true.
OptionrowHeight—Fixed row height in pixels. Defaults to 32.
OptionrowCount—Total number of rows.
MethodgetRenderedRowRange—Returns the half-open range of rendered row indices.
CallbackonRenderedRangeChange—Fires only when the rendered range changes.

Acceptance criteria

  • The number of rendered row elements is at most ceil(viewportHeight/rowHeight) + 2*overscanRows + 1. (met)
  • The scroll container's total scrollable height equals rowCount*rowHeight, as long as that stays below the browser limit handled in F12. (met)
  • Scrolling to any offset shows rows whose indices match floor(scrollTop/rowHeight). (met)
  • onRenderedRangeChange fires only when the rendered range actually changes. (met)
  • Changing rowHeight at runtime recomputes layout without a page reload. (met)