the singularity of being and nothingness
Archive for November, 2011
ExtJS 4: Filtering on Multiple Fields
Nov 23rd
Filtering ExtJS data stores is stupid-simple. When filtering, you have 2 main options:
- Filtering on a property (e.g., “field”)
- Filtering with a custom function
Ext.define('Person', { extend: 'Ext.data.Model', idProperty: 'id', fields: [ {'firstname', type:'string'}, {'middlename', type: 'string'}, {'lastname', type: 'string'} ] });
Ext.create('Ext.data.Store', { autoLoad: true, model: 'Person', storeId: 'PersonStore', proxy: { type: 'ajax', url: 'myurl.json', reader: { type: 'json', root: 'people' } } });Ok, now that we have those set up, let’s say that we want to filter our results to only those people whose last name contains “son” (like “Watson”). Using the property filter, we can do this very simply:
var store = Ext.data.StoreManager.lookup('PersonStore'); var peoplefilter = new Ext.util.Filter({ property: 'lastname', value: 'son', anyMatch: true, caseSensitive: false, root: 'data' }); store.filter(peoplefilter);
Nothing to it, right? There are two important parts here. First, for “property”, we are simply specifying the field in our Model which we want to filter on…in this case, “lastname.” Second, we specify that we want the filter to look at the “data” object of each record–otherwise, it will fail miserably 🙂
For simple filtering, using the “property” method will get you by pretty good. For More >
Quick Updates
Nov 11th
Just a quick note to let everyone know that I’m still alive! 🙂
The last several weeks have been *crazy*, and I’m also in the process of switching hosting companies. Once things settle down a bit (hopefully next week), I’ll be back to blogging more regularly.
Share this: