How to reset the paginator?

南楼画角 提交于 2021-01-28 04:21:45

问题


How to reset the paginator and go to the first page? this.page = 1 does not work correctly. Just in case, I'll explain that I do not use 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>

回答1:


You need to set pageIndex of paginator, but you will have to use ViewChild decorator to select that paginator, so in your component:

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

and in your method:

this.paginator.pageIndex = 0;



回答2:


I am using primeng. Please see below syntax to reset:

import { Paginator } from 'primeng/primeng';

@ViewChild('paginator') paginator: Paginator;


this.paginator.changePage(0);


来源:https://stackoverflow.com/questions/58004169/how-to-reset-the-paginator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!