[idea] Make second parameter of /list an Observable, not just the inner values
I have a list of employees. Every employee has a name and and active property, e.g.
{
name: "Dirk Postma",
active: true
}
In my view I'd like to be able to filter by active flag, for example:
this.filteredItems = af.database.list('employees', {
query: {
orderByChild: 'active',
equalTo: this.querySubject
}
});
toggleActiveFilter() {
this.showActive = !this.showActive;
this.querySubject.next(this.showActive);
}
This works, great stuff!
Now one step further: I'd like to be able to show either active employees or ALL employees (both active and inactive). I would like to have something like this:
this.filteredItems = af.database.list('employees', this.querySubject });
toggleActiveFilter() {
this.showActive = !this.showActive;
if (this.showActive) {
// Show active employees only
this.querySubject.next({
query: {
orderByChild: 'active',
equalTo: true
}
});
} else {
// show all employees
this.querySubject.next(null);
}
}
Basically: make the second parameter itself an Observable in stead of just the inner values of e.g. equalTo.
Is this an idea?
I'm not sure if exactly that is what we need but I think we should be able to accomplish it.
@dirkpostma Is that mean that way we can have filter on top of another filter? If so, that's really a good idea.
According to my understanding, right now there is no way we can do filter on top of filter, right? Like in your example, we can only get employees active, but can not get active employee with certain last name. Am I right?
It's not going to be possible to use multiple filter criteria since this isn't supported by the SDK.
It seems like it would be a nice addition to make this.query observable instead of this.querySubject.
For the original problem, could we not take advantage of the ordering criteria and simply using startAt, changing the setup as follows?
this.filteredItems = af.database.list('employees', {
query: {
orderByChild: 'active',
startAt: this.querySubject
}
});
toggleShowAll() {
this.showAll = !this.showAll;
// to include inactives, we "startAt" false
// to only include actives, we "startAt" true
this.querySubject.next(this.showAll? false : true);
}
Active conversation in #770.