Sencha Touch - Store



It is basically the collection of model instances. Stores can be static and dynamic as well. In a static store, we load data inline. In dynamic store, we fetch data from the server using ajax proxies.

Store base class is Ext.data.Store

Static Store

Ext.create('Ext.data.Store', {
   model: 'User', data: [
      { firstName: 'Greg',    lastName: 'Barry' },
      { firstName: 'Seth', lastName: 'Lemmons' },
      { firstName: 'Mitch', lastName: 'Simoens' },
      { firstName: 'Fred', lastName: 'Mosby' }
   ]
});

In store, we can perform sorting, filtering, and grouping of store data locally as well as remotely.

To perform sorting locally, we define the sorter and the field, based on which we need to sort the data.

Filter in key value pair as property be your field name and value be your value to be filtered.

Grouping can be performed with groupField in which we provide a field name based on which the grouping has to be done.

groupDir is to specify the direction - ascending or descending.

Ext.create('Ext.data.Store', {
   model: 'User', sorters: ['name', 'id'], filters: {
      property: 'name', value   : 'Ed'
   },
   groupField: 'age', groupDir: 'DESC'
});
sencha_touch_data.htm
Advertisements