Currently, I am working on implementing a filter for a table of users using pipes. While I have successfully made it work for filtering based on one selection, I am now attempting to extend this functionality to accommodate multiple selections. It's important to note that this is specifically for one column in the table. At the moment, the column contains names such as Adam, Brenda, Dan, Harry, and so on. Additionally, there may be multiple instances of the same name in the column, which should also be included in the filtered results. The pipe implementation I currently have looks like this:
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;
}
}
My HTML code for using the pipe is simple:
<table [mfData]="tableData | dataFilter : filterQuery" #mf="mfDataTable">
In this snippet, the `filterQuery` variable represents just a string. But my goal is to pass an array of names into `filterQuery` to retrieve the values accordingly. For instance, if the user column has entries like:
- Adam, Adam, Brenda, Dan, Harry, Harry, Harry
and I provide `filterQuery ['Adam' , 'Harry']`, I expect the output to be:
- Adam, Adam, Harry, Harry, Harry
I would appreciate any guidance or suggestions on modifying the code to achieve this desired functionality! I have tried incorporating loops within the transform function using `query: string[]`, but haven't been successful so far.
Thank you!