Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ZackDeRose/fde362c0f13559bae9b5061fa440c3b1 to your computer and use it in GitHub Desktop.
Save ZackDeRose/fde362c0f13559bae9b5061fa440c3b1 to your computer and use it in GitHub Desktop.
Initializing Subjects for Searching from "Angular CDK Tables" article
combineLatest(this.heroes$, this.searchFormControl.valueChanges)
.subscribe(([changedHeroData, searchTerm]) => {
const heroesArray = Object.values(changedHeroData);
if (!searchTerm) {
this.tableDataSource$.next(heroesArray);
return;
}
const filteredResults = heroesArray.filter(hero => {
return Object.values(hero).reduce((prev, curr) => {
return prev || curr.toString().toLowerCase().includes(searchTerm.toLowerCase());
}, false);
});
this.tableDataSource$.next(filteredResults);
});
this.searchFormControl.setValue('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment