简体   繁体   中英

Angular material table paginator is not updating after filter

I am filtering table data source using a multiselect selectbox value. Table records are getting updated when I select the options from select box. But paginator is not getting updated.

 @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>

In below image I am filtering only database. Table is getting updated based on filters. But paginator is showing all the records.

And also if I select all check box in table header its selecting all records instead of selecting 4 records which is shown in UI. 在此处输入图像描述

Have you tried initializing paginator again in your filter method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM