Skip to content

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

Closed

Description

@dirkpostma

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?

Activity

  1. agu-z commented on Aug 4, 2016

    @agu-z

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

  2. joyceview commented on Aug 14, 2016

    @joyceview

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

  3. katowulf commented on Aug 25, 2016

    @katowulf
    Contributor

    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);
    }
    
  4. davideast commented on Jan 13, 2017

    @davideast
    Collaborator

    Active conversation in #770.

  5. added a commit that references this issue on Jan 15, 2017
    ac01f4f
  6. added a commit that references this issue on Feb 9, 2017
    f9cb5c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp: databaseRealtime Database (src/database).

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions