The system currently has 3 search fields: 1. Name.... 2. Subject.... 3.Price....
Each of these filters works independently - when searching by name, only results matching that name are displayed; similarly for subject and price.
However, the challenge lies in enabling all filters to work together i.e. finding a person named "BOB" who teaches "English" at a price range of "500-600". How can we establish this connection between multiple filters?
https://i.sstatic.net/CV8ji.png
In the component.ts file:
filterSearch is an array containing all user data, while tempFilterSearch is used for displaying it in HTML
searchSubject($event) {
this.subject = $event.target.value;
if(this.price == null){
this.tempFilterSearch = this.filterSearch.filter((res) => {
return (
res.subject1.toLocaleLowerCase().match(this.subject.toLocaleLowerCase()) ||
res.subject2.toLocaleLowerCase().match(this.subject.toLocaleLowerCase()) ||
res.subject3.toLocaleLowerCase().match(this.subject.toLocaleLowerCase())
);
});
}else if(this.price != null){
this.tempFilterSearch = this.filterSearch.filter((res)=>{
console.log(res);
if((Number(res.price1))>=(Number(this.lowerValue))
&&(Number(res.price1))<=(Number(this.higherValue))
&&(res.subject1.match(this.subject)) || (res.subject2.match(this.subject))|| (res.subject3.match(this.subject))){
return res.subject1 || res.subject2 || res.subject3;
}
})
}
searchName() {
this.tempFilterSearch = this.filterSearch.filter((response)=>{
return response.fullName.toLocaleLowerCase().match(this.name.toLocaleLowerCase());
})
}
searchPrice($event) {
this.price = $event.target.value.split("-");
this.lowerValue = this.price[0];
this.higherValue = this.price[1];
if (this.subject == null) {
this.tempFilterSearch = this.filterSearch.filter((res) => {
if((Number(res.price1))>=(Number(this.lowerValue))&&(Number(res.price1))<=(Number(this.higherValue)))
return res.price1.toLocaleLowerCase();
});
}else if(this.subject != null){
this.tempFilterSearch = this.filterSearch.filter((res)=>{
if((Number(res.price1))>=(Number(this.lowerValue))
&&(Number(res.price1))<=(Number(this.higherValue)) ){
return res.price1.toLocaleLowerCase();
}
})
}
}
In the component.html file:
<div class="tutorWrapper" *ngFor="let element of tempFilterSearch">
I am seeking a solution to enable all filters to work simultaneously.