导航到下一页时,mat-table数据范围标签重置为初始标签

时间:2019-08-09 11:30:16

标签: pagination angular-material angular8 mat-table

我在分页中使用了角材数据表,但是当我单击下一页时,下面显示的数据范围标签将重置为初始值。 这是我的问题的照片,因此可以更好地了解它。

这是第二页,但仍然显示1-1(而不是6-6(6))

This is second page but still shows 1-1 of 1  instead of 6-6 of 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();
}

0 个答案:

没有答案