Skip to content

nthornton2010/ng-table-virtual-scroll

 
 

Repository files navigation

Virtual Scroll for Angular Material Table

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

npm npm Travis (.org) branch npm

Table of Contents

NPM

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

Import TableVirtualScrollModule

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

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

Configure the table

Data Source

The TableVirtualScrollDataSource extends the MatTableDataSource and must be used as the data source for the mat-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 headerHeight="56" rowHeight="48" 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)

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

This project uses Angular CLI to build the package.

$ npm run build:lib ng-table-virtual-scroll

Issues

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

About

Virtual Scroll for Angular Material Table

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 71.2%
  • HTML 19.1%
  • CSS 8.0%
  • JavaScript 1.7%