the singularity of being and nothingness
Posts tagged Data Store

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 >

Sencha: Creating Child Stores
Oct 11th
One of the things I <3 about Sencha is the data store. Â They are super-simple to create, but very powerful for creating robust, data-driven applications. Â The other day, I found myself creating 3 data stores that were extremely similar, simply because of the fact that the data returned was fairly complex and nested. Â You see, with a Sencha store, you define a “root” of your data, which is really just how the store’s Reader will treat the “rows” of data that are fed into the store. Â This works very well, but in my scenario, I was wanting to create a master store of data defined at the highest possible root, and then create child stores based on some of the nested objects belonging to my initial data set. Â So in this case, instead of making 3 remote calls to get the same, but differently-structured data, I wanted to make 1 request and use the result 2 more times for different stores.
At first, I looked to the store itself for something like a “copy” or “clone” method, but there was none. Â There IS an option for doing an “each” loop for every record, but that just seemed a bit overkill. Â But More >