Angular 6 MatTable Performance in 1000 rows.

前端 未结 7 847
無奈伤痛
無奈伤痛 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 05:30

    I was having an issue with Turneye's answer giving me an "expressionchangedafterithasbeencheckederror", so I took inspiration from jabu.hlong's answer. It turned 5-10 seconds of load time into less than a second.

    ngAfterViewInit() {
      this.dataSource.sort = this.sort;
      this.dataSource.paginator = this.paginator;
    
      setTimeout(() => {
        this.dataSource.data = getData(); // Or whatever your data source is
      });
    }
    

    A side note (mentioned because it seems to be in the same class of issue as the one I was having): I have found it best practice to set the sort before the paginator, because I have run into issues with the reverse when setting matSortActive.

    EDIT: Fixed issues with brackets and semicolons.

提交回复
热议问题