如何重设分页器? [英] How to reset the paginator?

查看:73
本文介绍了如何重设分页器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

推荐答案

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

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;
...

以及您的方法:

this.paginator.pageIndex = 0;

这篇关于如何重设分页器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆