I am using mat-table. It has a filter which works fine.
Filter happened against this below data (All columns)
const ELEMENT_DATA: Element[] = [
{posit
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.
generateTable(tableData: any) {
this.dataSource = new MatTableDataSource(tableData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.filterPredicate = (data: any, filter: string) => {
console.log(data);
console.log(filter);
let matchFound = false;
for (let column of this.displayedColumns) {
if(column in data) {
if(data[column]) {
matchFound = (matchFound || data[column].toString().trim().toLowerCase().indexOf(filter.trim().toLowerCase()) !== -1)
}
}
}
return matchFound;
}
}
Whenever you wish to apply the filter, update the filter property on dataSource to the string value to be searched.
applyFilter(searchValue: any) {
this.dataSource.filter = this.filterText.trim().toLowerCase();
}