Created
July 20, 2022 18:12
-
-
Save riapacheco/395548878bff85e2d638868a26ecfc1b to your computer and use it in GitHub Desktop.
Angular pipe to filter all values in an array of objects [no key/field name required]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class FilterAllPipe implements PipeTransform { | |
transform(value: any, searchText: any): any { | |
if (!searchText) { return value; } | |
return value.filter((data: any) => this.matchValue(data, searchText)); | |
} | |
matchValue(data: any, value: any) { | |
return Object.keys(data).map((key) => { | |
return new RegExp(value, 'gi').test(data[key]); | |
}).some(result => result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment