使用mat table一次加载7000行

问题描述 投票:0回答:1

我有这个代码:

@Input() data: Array<Users>;
@ViewChild(MatSort, { static: false }) sort: MatSort;
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
dataSource: MatTableDataSource<Users> = new MatTableDataSource();

ngAfterViewInit() {
    this.dataSource.paginator = this.paginator;
    this.dataSource.sort = this.sort;
    this.dataSource.data = this.data;
}

分页器和排序不起作用,我有全部 7000 行,而且速度非常慢。接下来我可以尝试什么?

javascript angular angular-material angular8
1个回答
1
投票

您必须覆盖数据源并保持正确的步骤顺序。

ngAfterViewInit() {
    this.dataSource = new MatTableDataSource<Users>(this.data);
    this.dataSource.sort = this.sort;
    this.dataSource.paginator = this.paginator;
}
© www.soinside.com 2019 - 2024. All rights reserved.