Virtual Scroll

A long list of same-height rows that renders only the rows on screen.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrVirtualScroll } from 'ngwr/virtual-scroll';

@Component({ imports: [WrVirtualScroll] })
export class MyComponent {}

Playground

<wr-virtual-scroll
  [items]="rows"
  [itemSize]="32"
  [height]="320"
>
  <ng-template let-row let-i="index">
    <div>{{ i + 1 }}. {{ row.label }}</div>
  </ng-template>
</wr-virtual-scroll>

Customize

Items
10000
Row Height (px)
32 px
Viewport (px)
320 px

API

NameDescriptionTypeDefault
itemsrequiredItems to render. The same array reference triggers no re-layout.readonly T[]—
itemSizePer-row pixel height. All rows must share this height.number32
heightViewport height: a number in px, or any CSS length.number | string256
minBufferPxPixels of rendered content kept above + below the viewport.numberitemSize * 4
maxBufferPxMaximum buffered pixels before recycling rows.numberitemSize * 8
trackBytrackBy for the inner *cdkVirtualFor.TrackByFunction<T>identity
scrollToIndex(i, behavior?)Programmatically scroll an index into view.(i: number, b?: ScrollBehavior) => void—
scrollToOffset(px, behavior?)Scroll to a pixel offset.(px: number, b?: ScrollBehavior) => void—
checkViewportSize()Re-measure the viewport after a size change the window does not see, such as a split pane or a parent that was hidden.() => void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/virtual-scroll's own element.

VariableDefaultDeclared on
--wr-virtual-scroll-thumb-radiusvar(--wr-border-radius-pill).wr-virtual-scroll

Dependencies

Angular CDKscrolling

See also