0

I am using Material table in my Angular project.

There is a provision to filter string and it working perfectly

myData: UserData[]; // Imagine its initialized
dataSource = new MatTableDataSource(myData);

applyFilter(filterValue: string)
{
  this.dataSource.filter = filterValue
}

Now, I want to filter with array of strings, but it's not working.

myData: UserData[]; // Imagine its initialized
dataSource = new MatTableDataSource(myData);

applyFilter(filteredValues: string[])
{
  this.dataSource.filteredData = filteredValues
}

Getting below error

Type 'String[]' is not assignable to type 'UserData[]'.
Type 'String' is not assignable to type 'UserData'.

Roy
  • 7,811
  • 4
  • 24
  • 47
karthick
  • 83
  • 7

1 Answers1

1

To be able to filter from datasource of type String[], you have to specify a filterpredicate.

this.dataSource.filterPredicate = (data: String, filter: string) => {
    return data.includes(filter);
};

This now return all the string that includes the 'filterValue'.