angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

[idea] Make second parameter of /list an Observable, not just the inner values

Open dirkpostma opened this issue 10 years ago • 4 comments

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?

dirkpostma avatar Jul 26 '16 13:07 dirkpostma

I'm not sure if exactly that is what we need but I think we should be able to accomplish it.

agu-z avatar Aug 04 '16 03:08 agu-z

@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?

joyceview avatar Aug 14 '16 00:08 joyceview

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);
}

katowulf avatar Aug 25 '16 16:08 katowulf

Active conversation in #770.

davideast avatar Jan 13 '17 16:01 davideast