Results 1 to 3 of 3

Thread: Set initial list filter value dynamically

  1. #1
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    66
    Answers
    1

    Default Set initial list filter value dynamically

    Hi all,

    This one has been beating me the last two days. I have a grid which has a column with a list filter on it. The list of values of course comes from the data loaded into the backing store. The requirement I have is that when the store is loaded, the grid should be filtered to show all records EXCEPT those with one specific value.

    The code that was written before we migrated to 6.0.2 basically did a remote call, called load() on the store, then did a filterBy() on the store that rejected any records with the specific value. Easy enough, and I BELIEVE it worked.. I say "believe" because I'm not 100% sure based on what I'm seeing now...

    ...which is that any time you click an item in the filter list menu, specifically that one value that gets rejected, the filterBy function fires again, which of course rejects that one specific value. Result: you can never actually display the records with that one specific value now.

    I've tried so many different ways to tackle this without success. It seems like all I really need to be able to do is update the filter when I load the store and say "select every available option EXCEPT this one" and that should do the trick, but that doesn't seem like something that ExtJS lets you do.

    So, I'm not sure if this is a regression since 4.0.1 which we migrated to 6.0.2 from or whether it never worked and was just now discovered, but either way I can't seem to figure out how to do an initial filtering like this and have it still work when the user manually changes the filter later. filterBy() doesn't seem to be the right answer given that it fires every time they change the filter and unless in that function I can tell whether I'm doing the filtering initially or as a result of the user clicking an item in the filter list I'm kind of dead in the water.

    Any hints from anyone? Thanks!

  2. #2
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    I have posted a way to dynamically set grid list filter value some time ago here. It's not a "proper" way to do it because it uses private methods and variables but seems to work reliably for now and I don't think there is any other way to do it without extending the original filter class.

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2010
    Posts
    66
    Answers
    1

    Default

    Quote Originally Posted by hakimio View Post
    I have posted a way to dynamically set grid list filter value some time ago here. It's not a "proper" way to do it because it uses private methods and variables but seems to work reliably for now and I don't think there is any other way to do it without extending the original filter class.
    Thanks, that looks similar to something I tried but couldn't make work. I probably messed something up that you got right

    For posterity, what I wound up doing was this:

    Code:
    // Load records into myGrid here, then...
    myAppObject.initialLoad = true;
    myGrid.filterBy(
      function(inRecord) {
        if (myAppObject.initialLoad) {
          return inRecord.get("errcd") != "123" ? true : false;
        } else {
          return true;
        }
      }
    );
    myAppObject.initialLoad = false;
    It's a totally simplistic and dumb way to do it, but it (basically) works how I need it to The if branch only executes during the initial load and the else branch kicks in any time the user changes a filter, effectively "skipping" this filter in a sense.

    The only "problem" is that initially, the filter list for that column should really have everything EXCEPT records with "123" in the errcd field checked so as to accurately reflect what's being displayed, but that's not the case. However, it's a fairly minor problem for my particular use case and, in a way, really isn't a problem per se (or so I've managed to convince the BA's! LOL)

Similar Threads

  1. Replies: 3
    Last Post: 21 Oct 2016, 11:50 AM
  2. Replies: 2
    Last Post: 20 May 2014, 2:29 AM
  3. Replies: 1
    Last Post: 4 Sep 2013, 5:27 AM
  4. Replies: 2
    Last Post: 20 Dec 2012, 3:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •