API Reference

The pagination and skeleton features (page, pageSize, loading, pageNeeded, pageChanged, scrollToPage, ngxVirtualGridSkeleton) require 22.1.0+, 21.1.0+, 20.1.0+, or 19.1.0+.

Inputs

InputTypeDefaultDescription
itemsunknown[][]Array of data items to render
bufferSizenumber3Number of extra rows to render above and below the viewport
loadMoreThresholdnumber0.8Scroll ratio (0-1) at which the loadMore event fires. Measured within the loaded data (skeletons and unloaded pages above are excluded), so deep-linked pages don't fire immediately.
scrollParentHTMLElement | nullnullCustom scroll container. Uses window if null
pagenumber0The page (0-indexed) that the first item in items belongs to. Keep it set to the lowest loaded page - it creates page * pageSize items of virtual space above the loaded data.
pageSizenumber0Number of items per page. Enables pagination when > 0. Space above loaded data is calculated from page * pageSize.
loadingbooleanfalseWhen true and a skeleton template is provided, renders skeleton placeholders in visible slots that don't have data. The skeleton count matches the number of items the virtual scroller would normally render.

Outputs

OutputTypeDescription
loadMorevoidEmits when the scroll position crosses the loadMoreThreshold within the loaded data. Re-arms when more items are appended; prepending an earlier page does not re-arm it.
pageNeedednumberAsks for earlier pages: emits page - 1 when the viewport nears the top of loaded data, or the viewport's own page after a fast scroll jumps above it. Asks again on each page change until the viewport is covered. Use loadMore for pages below.
pageChangednumberEmits the current page number when the viewport center crosses a page boundary. Useful for updating the URL.

Methods

MethodDescription
scrollToIndex(index: number)Scroll to bring the item at the given index into view
scrollToOffset(pixels: number)Scroll to an absolute pixel offset within the grid
scrollToPage(page: number)Scroll to the start of the given page (requires pageSize > 0)
refresh()Re-measure dimensions and recalculate layout

Template Context

The ngxVirtualGridItem template receives the following context:

VariableTypeDescription
$implicitTThe data item
indexnumberThe item's global index. Same as the array index in non-paginated mode; offset by page * pageSize in paginated mode

Skeleton Template

Provide a skeleton template using the ngxVirtualGridSkeleton directive. When the loading input is true, skeleton placeholders are rendered in visible slots that don't have data. The library automatically calculates the correct number of skeletons to fill the viewport.

<ngx-virtual-grid [items]="items" [loading]="isLoading">
  <ng-template ngxVirtualGridItem let-item>
    <app-card [data]="item"></app-card>
  </ng-template>

  <ng-template ngxVirtualGridSkeleton>
    <app-card-skeleton></app-card-skeleton>
  </ng-template>
</ngx-virtual-grid>

The ngxVirtualGridSkeleton template receives $implicit as the global index of the skeleton slot.

Zoneless Apps

The library works with both zoned and zoneless Angular apps. In zoneless mode, the loadMore output emits from a raw scroll event listener. If your handler modifies component state, use signals so the view updates:

items = signal<Item[]>([]);

onLoadMore(): void {
  this.items.update(current => [...current, ...newItems]);
}