Created
March 9, 2018 15:07
-
-
Save jsanta/9666206c0071f6c30b458418e114b5a9 to your computer and use it in GitHub Desktop.
toggleFilter function. Adds or removes a simple search filter from the activeFilters array. Then it filters the original data to a filteredData array.
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
private activeFilters: Array<string> = []; | |
toggleFilter(_filter: string) { | |
const filterIdx: number = findIndex(this.activeFilters, (v) => v === _filter ); | |
if (filterIdx !== -1) { | |
pullAt(this.activeFilters, [ filterIdx ]); | |
} else { | |
this.activeFilters.push(_filter); | |
} | |
this.filteredData = filter(this.data, (v) => includes(this.activeFilters, v.color)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beware that this code uses lodash to search, remove and check active filters (findindex, pullAt, filter and includes functions).
Import them from lodash-es like this: