Angular 6 MatTable Performance in 1000 rows.

前端 未结 7 813
無奈伤痛
無奈伤痛 2020-12-03 04:56

I\'m using angular material in my project and I\'m using Mat-Table to render 1000 Product/row per table. When Change pagination (we use backend pagination) of table to 1000

7条回答
  •  無奈伤痛
    2020-12-03 05:29

    Not sure if this will help your situation as there's no code but we've found that the MatTable loads very slowly if a large data set is set before you set the datasource paginator.

    For example - this takes several seconds to render...

    dataSource: MatTableDataSource = new MatTableDataSource();
    @ViewChild(MatSort) sort: MatSort;
    @ViewChild(MatPaginator) paginator: MatPaginator;
    
    ngOnInit() {
      this.dataSource.data = [GetLargeDataSet];
    }
    
    ngAfterViewInit() {
      this.dataSource.sort = this.sort;
      this.dataSource.paginator = this.paginator;
    }
    

    ...but this is fast

    ngOnInit() {
      // data loaded after view init 
    }
    
    ngAfterViewInit() {
      this.dataSource.sort = this.sort;
      this.dataSource.paginator = this.paginator;
    
      /* now it's okay to set large data source... */
      this.dataSource.data = [GetLargeDataSet];
    }
    

    Incidentally, we were only finding this issue the second time we access the component as the large dataset from server was being cached and was immediately available the second time component was accessed. Another option is to add .delay(100) to your observable if you want to leave that code in the ngOnInit function.

    Anyway, this may or may not help your situation.

提交回复
热议问题