I am using mat-table. It has a filter which works fine.
Filter happened against this below data (All columns)
const ELEMENT_DATA: Element[] = [
{position: 14598, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 24220, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 39635, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 42027, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 53216, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 60987, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 70976, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 81297, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 90975, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 18879, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
{position: 11209, name: 'Sodium', weight: 22.9897, symbol: 'Na'}
];
But Now I am trying to change the filter because I want is filter just for "position", "name", "symbol"
column. I have gone through this example but Filtering specific column in Angular Material table in angular 5.
I did not understand please help me on this
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.
You have to override the
filterPredicate
of your dataSource.Here's an example of how to do it: Working demo
Essentially, you want to specify what properties in your data the filter is applied to:
Adding to bugs' answer. Here's a more elaborate implementation,
Please feel free to suggest edits, if this could be improved
In Angular Material Tables, we can create column based filters from data itself.
Source Link
Demo Link
For that, we need to override the filterPredicate method with customFilter() method
Check complete working code here