3

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

Edric
  • 24,639
  • 13
  • 81
  • 91
c0micrage
  • 1,118
  • 2
  • 21
  • 56

1 Answers1

1

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')
c0micrage
  • 1,118
  • 2
  • 21
  • 56