简体   繁体   中英

How to modify the way the data table filter works in Angular Material?

I am trying to use the filter in Angular Material Data Table like -

If I search for " MATCHED ", then both " MATCHED " and " UNMATCHED " comes up in the status column of the Data table.

I know that it is because the data object is reduced and concatenated and the filter is applied( from the Angular Material Docs ).

I want to display only the " MATCHED " status, if is search for matched. So I am looking for a filter that will do exact word filtering instead of substrings. How to proceed ?

I read this post but I was not able to proceed.

Here you go - StackBlitz

Following on from the answer that you referred to we need to define filterPredicate :

export class TableFilteringExample {
  displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
  dataSource = new MatTableDataSource(ELEMENT_DATA);

  constructor() {
    this.dataSource.filterPredicate = (data: PeriodicElement, filter: string) => {
      return data.name === filter;
    }
  }

  applyFilter(filterValue: string) {
    this.dataSource.filter = filterValue.trim();
  }
}

Note that toLowerCase() has been removed from filterValue.trim() .

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