How to create custom filtering using MatTableDataSource in angular 5?
Asked Answered
W

1

9

In Angular material official website Angular Material Table it is mentioned that filterPredicate: ((data: T, filter: string) => boolean) will filter data based on a specific field. But don't know how to start. Is there any example is present for this.

Warthog answered 19/4, 2018 at 17:25 Comment(0)
T
15

This answer seems to show how to use the filter predicate:

https://mcmap.net/q/409510/-filtering-specific-column-in-angular-material-table-in-angular-5-duplicate

It works like so:

this.dataSource.filterPredicate = (data: MyObject, filter: string) => {
  return data.property == filter;
};

this.dataSource.filter = myValue;
Typical answered 19/4, 2018 at 17:55 Comment(2)
Thanks, @peter for the response it's working correctly.Warthog
would you do this in ngOnInit?Farnesol

© 2022 - 2024 — McMap. All rights reserved.