如何重设分页器?

时间:2019-09-19 05:21:51

标签: angular angular-material

如何重设分页器并转到首页? this.page = 1无法正常工作。以防万一,我将说明我不使用MatPaginator

ts:

  pageSizeOptions = [5, 10, 25, 50, 100];
  pageSize = 5;
  page = 1;

   applyFilter() {
    let searchFilter: any = {
      filterValue: this.search
    };
    this.categories.filter = searchFilter;
    if (this.page !== 1) {
      this.page = 1;
    } else {
      this.load();
    }
  }

  onPaginateChange(event) {
    this.page = event.pageIndex + 1;
    this.pageSize = event.pageSize;
    this.load();
  }

html:

<mat-paginator [pageSizeOptions]="pageSizeOptions" [length]="totalItems" [pageSize]="pageSize"
      (page)="onPaginateChange($event)" showFirstLastButtons [disabled]="!isActive">
</mat-paginator>

2 个答案:

答案 0 :(得分:1)

您需要设置pageIndex的分页器,但是必须使用ViewChild装饰器来选择该分页器,因此在您的组件中:

@ViewChild(MatPaginator, {static:false}) paginator: MatPaginator;
...

以及您的方法中

this.paginator.pageIndex = 0;

答案 1 :(得分:0)

我正在使用primeng。请参见以下语法进行重置:

import { Paginator } from 'primeng/primeng';

@ViewChild('paginator') paginator: Paginator;


this.paginator.changePage(0);