Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ng-table-virtual-scroll

diprokon290.8kMIT1.6.1TypeScript support: included

Virtual scroll for for Angular Material Table

angular, material, scroll, virtual scroll, table

readme

Virtual Scroll for Angular Material Table

An Angular Directive, which allow to use virtual scrolling in mat-table

Demo npm Build & Test License

Table of Contents

Installation

NPM

$ npm install -save ng-table-virtual-scroll

Version compatibility

Angular version Library version
>= 15 latest
13 - 14 1.5.*
<= 12 1.3.*

Usage

Import TableVirtualScrollModule

import { TableVirtualScrollModule } from 'ng-table-virtual-scroll';

@NgModule({
  imports: [
    // ...
    TableVirtualScrollModule
  ]
})
export class AppModule { }

Note: you need to install and configure virtual scrolling (ScrollingModule) and mat-table (MatTableModule) before. TableVirtualScroll only make them work together properly

Configure the table

Data Source

The TableVirtualScrollDataSource extends the MatTableDataSource and must be used as the data source for the mat-table (CdkTableVirtualScrollDataSource for cdk-table)

Note: without TableVirtualScrollDataSource the directive won't work

import { TableVirtualScrollDataSource } from 'ng-table-virtual-scroll';

@Component({...})
export class MyComponent {

  dataSource = new TableVirtualScrollDataSource();

}

Directive

The tvsItemSize directive makes the magic

<cdk-virtual-scroll-viewport tvsItemSize="48" headerHeight="56" style="height: 400px;">
    <table mat-table [dataSource]="dataSource">
    ...
    </table>
</cdk-virtual-scroll-viewport>

Make sure, you set the height to the <cdk-virtual-scroll-viewport> container

Also, you can provide additional properties:

tvsItemSize -> the row height in px (default: 48)

headerHeight -> the header row height in px (default: 56)

footerHeight -> the footer row height in px (default: 48)

headerEnabled -> is the header row in the table (default: true)

footerEnabled -> is the footer row in the table (default: false)

bufferMultiplier -> the size of rendered buffer. The bufferMultiplier * visibleRowsCount number of rows will be rendered before and after visible part of the table.

CdkTable

cdk-table from CdkTableModule is also supported. Just use CdkTableVirtualScrollDataSource as datasource

Issues

If you identify any errors in the library, or have an idea for an improvement, please open an issue.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

1.6.1 - 2024-03-31

Fixed

  • #124: Call onDataLengthChanged only when it's changed
  • #129: Trigger initial sticky position

1.6.0 - 2023-02-20

Added

  • Support for Angular and Angular Material 15 (#107, #111)

Removed

  • Support for Angular 14 and less

1.5.1 - 2023-02-18

Fixed

  • #101: Sticky footer

1.5.0 - 2023-02-05

Added

  • Support for cdk-table (#79)

Fixed

  • #109: Update scroll position when new data is less than current scroll position

1.4.1 - 2022-07-22

Fixed

  • #105: Update of column definitions triggers sticky update

1.4.0 - 2022-01-26

Changed

  • Build with Ivy (View Engine is no longer available in Angular v13)