custom filter in mat-table

后端 未结 4 795
深忆病人
深忆病人 2020-11-29 01:54

I\'m using mat-table. It has a filter which works fine with doc example:

From https://material.angular.io/components/table/overview, the original code is:



        
4条回答
  •  离开以前
    2020-11-29 02:47

    Don't forget to apply .trim().toLowerCase() on your data or you may encounter unexpected results. See my example below:

    this.dataSource.filterPredicate = (data:
      {name: string}, filterValue: string) =>
      data.name.trim().toLowerCase().indexOf(filterValue) !== -1;
    
    applyFilter(filterValue: string) {
        this.dataSource.filter = filterValue.trim().toLowerCase();
    }
    

提交回复
热议问题