Answer the question
In order to leave comments, you need to log in
How to make a pipe to search results for the entire table?
I'm having trouble creating a pipe to look up values across an entire table.
https://plnkr.co/edit/PSU0Hh?p=info
In my example, the filter only looks for one field. How to make a pipe to search for values in the entire table?
Answer the question
In order to leave comments, you need to log in
Obviously, you need to iterate over all the fields, instead of checking for a specific one. For example like this :
class FilterPipe implements PipeTransform {
transform(items: any[], term): any {
const keys = items.length ? Object.keys(items[0]) : null;
return term && keys
? items.filter(item => keys.some(key => item[key].toString().indexOf(term) !== -1))
: items;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question