I am trying to filter an Angular Material mat-table for a column that only contains boolean. I read here that datasource.filterPredicate can be used to filter the collection but I found out that the call uses a string parameter. Here is my code so far
this.dataSource.filterPredicate = (data: T, filter: boolean) => !filter || data.isCompleted== filter;
I also tried the following but nothing happens
this.dataSource.filteredData.filter(f => f.isCompleted== filter);
How can I filter the datasource based on a boolean column?
Thanks
After playing around with mat-table, filterPredicate, I got it work. Here is the fix
I can't compare to a boolean value. To get this to work, I pass in a string of 'true' or 'false'
TS
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
HTML
applyFilter('true')
applyFilter('false')
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