Component

Virtual Scroll

Fixed-size virtual scroll viewport. Thin wrapper around CDK's cdk-virtual-scroll-viewport with ngwr theming + sensible buffer defaults. Renders only the rows actually on screen, so a 100k-row list costs the same as a 30-row list.

Import

import { WrVirtualScroll } from 'ngwr/virtual-scroll';

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 — number = px, or any CSS length string.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()Force a viewport size recheck (after host resize outside ResizeObserver).() => void