Hybrid View

  1. #1
    Sencha Premium Member
    Join Date
    Apr 2009
    Posts
    162
    Answers
    5
    Vote Rating
    7
    jhoweaa is on a distinguished road

      0  

    Default Unanswered: Store Filtering Question

    Unanswered: Store Filtering Question


    I don't know if this is a bug or just a misunderstanding on my part. I'm using Ext JS 4.1.3. I have a store which uses a model which has a field called 'account_id'. When the store is populated, it would have records like this:

    Code:
    Record Id, Account ID, Name, Other Stuff
    
    1,1,Foo,Stuff
    2,1,Bar,Stuff
    3,1,Baz,Stuff
    4,2,FooBar,Stuff
    ...
    10,20,MyFoo,stuff
    11,20,MoreFoo,Stuff
    ...
    The upshot is that I have a store containing a bunch of records. Each record is associated with a particular 'account' and a given account may have many records in this store. When I display this information I want to filter items by account number. To do this, I have some code which does the following:

    Code:
    setActiveAccount: function(accountId) {
       var myStore = this.getStore();
       myStore.clearFilter(true);
       myStore.filter({property: 'account_id', value: accountId});
    }
    This *mostly* works. The problem comes when I try to filter on account ID #2. It seems that the store is doing a regex match on the account id value (in this case '2') and it matches not only the records with an account id of 2, but also those with account ids of 20, 21, 22, etc. In stepping through the code in the debugger, I can see that my filter is getting translated into a regex of the form "^2" which seems to indicate that the store will include any record who has an account ID that starts with '2'.

    What I want is an exact match. It seems that if I'm passing in an explicit value and not a regex, the filter should perform an exact match. Am I missing something? How do I get the store to do an exact match filter instead of this partial match?

    Thanks.

    Jim

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2009
    Posts
    162
    Answers
    5
    Vote Rating
    7
    jhoweaa is on a distinguished road

      0  

    Default


    Upon further investigation, it seems that if I use the following when specifying the filter, I get the exact match:

    Code:
    myStore.filter({property: "account_id", value: accountId, exactMatch: true});
    It's not clear from the documentation how matching works. I had to look at the source code for Filter to figure out that exactMatch defaults to false. I had to look at the Store source code to learn that when I passed in my filter configuration it was using that as the config to create an Ext.util.Filter object. I realize that the filtering example shows the user passing in an explicitly created Filter object, but it would be better if the documentation made it clear that you were passing in a filter config and to see the other options you should look at Ext.util.Filter.

    Thanks.

    Jim

Tags for this Thread