2 * Created by cp2122 on 1/4/2018.
4 import { Pipe, PipeTransform } from '@angular/core';
5 import * as _ from 'lodash';
10 export class DataFilterPipe implements PipeTransform {
12 transform(items: any, searchStr: string, keys?: string[][]): any {
13 if (items != null && items.length > 0 && !_.isNil(searchStr)) {
16 if (_.isNil(keys) || keys.length === 0) {
17 keys = Object.keys(items[0]).map((key)=> new Array(key) );
19 for (const item of items) {
20 for(const key of keys) {
22 let val: string = DataFilterPipe.getDeepObjectValueByKeys(item, key);
23 if (!_.isNil(val) && val.toLowerCase().includes(searchStr.toLowerCase())) {
32 /**********************************************************************
33 get value from obj data by array of keys.
34 @keys: all table column and keys
36 ************************************************************************/
37 static getDeepObjectValueByKeys(rowData: any , keys: string[]) : string {
38 let obj = rowData[keys[0]];
42 for(let i = 1; i < keys.length ; i++){
45 return obj.toString();