You can override the default filtering behaviour by defining a custom filterPredicate
function (see https://material.angular.io/components/table/overview#filtering). For your example, try something like the following to match on exact symbol or partial name (both case insensitive) separated by space:
@Component({
selector: 'table-editing-example',
styleUrls: ['table-editing-example.css'],
templateUrl: 'table-editing-example.html',
})
export class TableEditingExample {
displayedColumns = ['position', 'name', 'weight', 'symbol', 'fav'];
dataSource = new MatTableDataSource(ELEMENT_DATA);
ngOnInit() {
this.dataSource.filterPredicate = this.filterObject;
}
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
filterObject(obj, filter): boolean {
return filter.split(' ').some(
item => obj.name.toLowerCase().indexOf(item) >= 0 || obj.symbol.toLowerCase() == item
);
}
}