angular - 动态数据分页
问题描述
我有一个服务调用,我从 HTTP 请求中获取数据,现在数据带有计数和响应,每次响应的计数为 10,但实际上,数据超过 10,如 50,需要分页,意味着后端发送分页数据我在 mat-table 中使用 mat-paginator 来显示分页,它显示了 10 个列表的数据,但是对于剩余的分页不起作用
<mat-paginator
hidePageSize
[length]="count"
[pageSize]="pageSize"
(page)="onPaginationChange($event)"
>
</mat-paginator>
关于如何做到这一点的任何想法?
data: {
count: 44
result: [,…]
}
这就是我得到的
public count: number;
public memberList: ITeamMember[];
public pageSize: number;
public dataSource: MatTableDataSource<IMemberList> = new MatTableDataSource<
IMemberList
>();
private sort: MatSort;
private paginator: MatPaginator;
@ViewChild(MatSort) set matSort(ms: MatSort) {
this.sort = ms;
this.setDataSourceAttributes();
}
@ViewChild(MatPaginator) set matPaginator(mp: MatPaginator) {
this.paginator = mp;
this.setDataSourceAttributes();
}
ngOnInit(): void {
this.isDataLoading = true;
this.createTeamMemberList();
}
private setDataSourceAttributes(): void {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
ngAfterViewInit(): void {
this.cd.detectChanges();
}
public createTeamMemberList(): void {
this.teamService.getTeamMembers().subscribe(
(response: TeamMemberResponse) => {
this.dataSource = new MatTableDataSource<IMemberList>(
this.individualMember
);
this.dataSource.paginator = this.paginator;
this.pageSize = response.result.length;
this.count = response.count;
},
(error: Error) => {
this.isDataLoading = true;
this.sharedService.openErrorSnackBar(error);
}
);
}
解决方案
推荐阅读
- ios - 推送通知点击获取 url 并在 View Controller , iOS , Swift4.2 中显示
- javascript - 如何阻止 css translate 将元素带到前面?
- mysql - MySQL 多个唯一列
- jquery - Wordpress AJAX 调用返回未定义
- python - 递归上传目录(其中包含目录)到 FTP
- ionic-framework - 在生产构建离子3中没有获得本地通知声音
- javascript - 修复javascript中的变量增量
- redux - 使用 react-redux 如何在异步更新调用后端之前实现即时 UI,如果更新不成功则回滚?
- c# - 如何在 C# 中访问 JSON 对象的结果
- node.js - 带有node.js的对话流你如何切换意图