问题描述
从这篇SO 帖子中我了解到,为了处理大型数据集,您应该设置dataSource.paginator 在ngAfterViewInit中的 dataSource.data之前.
From this SO post i learned that in order to deal with large datasets you should set dataSource.paginator before dataSource.data in ngAfterViewInit.
但是,在执行此操作时,我无法使用this.paginator.pageIndex设置初始pageIndex.
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
当我将数据加载到ngOnInit中,并将分页器加载到ngAfterViewInit中时,我可以设置初始pageIndex:
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
推荐答案
您可以尝试以下操作:
ngOnInit() {
this.dataSource.paginator = this.paginator;
}
ngAfterViewInit() {
setTimeout(() => {
this.paginator.pageIndex = 3;
this.todos$.subscribe((todos) => this.dataSource.data = todos);
}, 0);
}
这篇关于处理大型数据集时,无法在mat-paginator中设置初始pageIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!