簡體   English   中英

Angular 素材表分頁器在過濾后未更新

[英]Angular material table paginator is not updating after filter

我正在使用多選選擇框值過濾表數據源。 當我從 select 框中選擇 select 時,表記錄正在更新。 但是分頁器沒有更新。

 @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; ngOnInit() { this.dataSource.paginator = this.paginator; this.dataSource.filterPredicate = (tdata: Catalog, filter: string) => { return this.filters.length > 0? this.filters.some(e => e === tdata.type): true; }; } applyFilter() { this.tdataSource.filter = 'trigger filter'; }
 <mat-form-field> <mat-label>Filters</mat-label> <mat-select multiple [(value)]="filters"> <mat-option *ngFor="let item of options" [value]="item" (click)="applyFilter(item)"> {{item}} </mat-option> </mat-select> </mat-form-field>

在下圖中,我只過濾數據庫。 表正在根據過濾器進行更新。 但是分頁器正在顯示所有記錄。

而且,如果我 select 表 header 中的所有復選框,它會選擇所有記錄,而不是選擇 UI 中顯示的 4 條記錄。 在此處輸入圖像描述

您是否嘗試在過濾器方法中再次初始化分頁器:

applyFilter(filterValue: string) {
  this.dataSource.filter = filterValue.trim().toLowerCase();
  setTimeout(() => this.dataSource.paginator=this.paginator;
  setTimeout(() => this.dataSource.sort = this.sort);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM