我在分页中使用了角材数据表,但是当我单击下一页时,下面显示的数据范围标签将重置为初始值。 这是我的问题的照片,因此可以更好地了解它。
这是第二页,但仍然显示1-1(而不是6-6(6))
这是我的代码:
table.component.html
<mat-table [dataSource]="dataSource">
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef> E-Mail </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="description">
<mat-header-cell *matHeaderCellDef> Phone </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.description}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons
(page)="getNext($event)" [length]="resultsLength"></mat-paginator>
table.component.ts
filter = {
page: "1",
limit: "5",
sortName: 'name',
sortOrder: 'asc'
};
getAllData() {
this._http.get<any>(url, { headers: headers }).subscribe(res => {
this.blogs = res;
this.dataSource = new MatTableDataSource(this.blogs['items']);
this.dataSource.paginator = this.paginator;
this.resultsLength = this.blogs['total'];
})
}
getNext(value) {
this.filter.page = value.pageIndex + 1;
this.getAllData();
}