I'm currently trying to filter a table of users using pipes. I get it to work for 1 selection, but I'm trying to expand it to multiple selection. Keep in mind this is for only one column of the table. As of right now I have a column of users such as: Adam, Brenda, Dan, Harry. etc.. Keep in mind this column might multiple of the same name which I want to return as well. My current pipe implementation is as follows:
import * as _ from 'lodash';
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'dataFilter'
})
export class DataFilterPipe implements PipeTransform {
transform(array: any[], query: string): any {
if (query) {
return _.filter(array, row=>row.user.indexOf(query) > -1);
}
return array;
}
}
And my html is simply:
<table [mfData]="tableData | dataFilter : filterQuery" #mf="mfDataTable">
Where the filterQuery is just a string. Basically what I want to do is pass in an array of names to that filterQuery so it returns the values based on that. So lets say the rows of the user column had:
- Adam, Adam, Brenda, Dan, Harry, Harry, Harry
and I passed in filterQuery ['Adam' , 'Harry'] I would get back:
- Adam, Adam, Harry, Harry, Harry
Any help on modifying the code to help achieve this would be appreciated! I tried doing some loops in the transform function with the query: string[] but no luck yet.
Thanks!