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.
Save this question. Show activity on this post. export class TableFilteringExample { displayedColumns = ['position', 'name', 'weight', 'symbol']; dataSource = new MatTableDataSource(ELEMENT_DATA); applyFilter(filterValue: string) { filterValue = filterValue.
Material has implemented its own search feature you can override it by updating the filterPredicate property on the date source. Call the generateTable function on ngOninit() life cycle. Whenever you wish to apply the filter, update the filter property on dataSource to the string value to be searched.
Default filterPredicate function combines all columns values and checks if the filter string exists in the combined string. filterPredicate uses a special character(◬) in between the column values while appending.
This answer seems to show how to use the filter predicate:
https://stackoverflow.com/a/50174938/6130716
It works like so:
this.dataSource.filterPredicate = (data: MyObject, filter: string) => {
return data.property == filter;
};
this.dataSource.filter = myValue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With