【发布时间】:2021-06-07 00:21:38
【问题描述】:
我正在将 JSON 数据从后端 asp.net core c# API 加载到 ANGULAR 材料表,但问题是整个 100 行 JSON 数据加载到第一页我已经设置了如下分页器:
<mat-paginator showFirstLastButtons [pageSizeOptions]="[25, 50, 100]"></mat-paginator>
如您所见,分页器应该加载前 25 行,但它会加载第一页上的所有 100 行。下面是我调用我的 ASP.NET CORE C# Web API 以将 JSON 数据获取到 mat 表的方法。
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
dataSource : MatTableDataSource<BugsData>;
selection = new SelectionModel<BugsData>(true, []);
bugsData:any;
ngOnInit(){
this.spinner.show();
this.http.get('https://localhost:44318/api/Bugs/ListofBugs?projectid='+this.route.snapshot.params['id']+'').subscribe(
(data:any) => {
if(data.message!=null){
this.snackbar.open(data.message, '✖',{
duration:4000,
horizontalPosition:'center',
verticalPosition:'top'
}),
this.spinner.hide()
}else{
console.log(data);
this.bugsData=data,
this.dataSource = new MatTableDataSource<BugsData>(this.bugsData),
this.dataSource.sort = this.sort,
this.dataSource.paginator = this.paginator,
this.spinner.hide()
}
}
)
}
}
这段代码有什么问题?
【问题讨论】:
-
如果有人想了解有关此问题代码的更多信息,请告诉我这里有空,并会尽快回复。
-
能否请您更新包含 mat-table 和 mat-paginator 的 html 代码。
-
您将整个响应分配给数据源。您应该只将响应的前 (25 / 50 / 100) 项分配给 dataSource。触发下一页时,您需要使用下一个 (25/ 50 /100 ) 项覆盖 dataSource。 Paginator 将不负责加载“n”号。表中的项目。您需要通过加载'n' no 来处理它。每次在表中的项目。
-
@MaruthiEranki 兄弟,如上所述,如何将数据分配给数据源????
标签: c# json angular pagination angular-material