1

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.

Saif Ali
  • 527
  • 5
  • 9
  • 22

1 Answers1

1

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().

camden_kid
  • 12,591
  • 11
  • 52
  • 88
  • please can you go through- https://stackoverflow.com/questions/52144473/how-to-filter-out-the-data-between-a-start-and-end-date-using-filterpredicate-in @camden_kid – Saif Ali Sep 03 '18 at 06:51