Not able to set initial pageIndex in mat-paginator when dealing with large datasets

十年热恋 提交于 2020-01-06 04:55:12

问题


From this SO post i learned that in order to deal with large datasets you should set dataSource.paginator before dataSource.data in ngAfterViewInit.

However when doing this I am not able to set an initial pageIndex using this.paginator.pageIndex.

https://stackblitz.com/edit/angular-mat-table-v2

When I load my data in ngOnInit and the paginator after this in ngAfterViewInit, I am able to set the initial pageIndex:

https://stackblitz.com/edit/angular-mat-table-v1


回答1:


You can try this:

  ngOnInit() {
     this.dataSource.paginator = this.paginator;
  }

  ngAfterViewInit() {
    setTimeout(() => {
     this.paginator.pageIndex = 3;
     this.todos$.subscribe((todos) => this.dataSource.data = todos);
    }, 0);
  }


来源:https://stackoverflow.com/questions/58518445/not-able-to-set-initial-pageindex-in-mat-paginator-when-dealing-with-large-datas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!