View Full Version : Store Filtering Question

29 Jan 2013, 8:39 AM
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:

Record Id, Account ID, Name, Other 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:

setActiveAccount: function(accountId) {
var myStore = this.getStore();
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?



29 Jan 2013, 8:54 AM
Upon further investigation, it seems that if I use the following when specifying the filter, I get the exact match:

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.