View Full Version : how to filter store data from view

30 Apr 2014, 9:41 AM

Ext.create('Ext.data.Store', { storeId: 'sid', fields: ['name', 'enable', 'label', 'maxlength', 'order'], data: { 'items': [ { 'name': 'Lisa', "enable": true, "label": "555-111-1224", 'maxlength': 5, 'order': 3 }, { 'name': 'Bart', "enable": false, "label": "555-222-1234", 'maxlength': 5, 'order': 3 }, { 'name': 'Homer', "enable": true, "label": "555-222-1244", 'maxlength': 5, 'order': 3 }, { 'name': 'Marge', "enable": false, "label": "555-222-1254", 'maxlength': 5, 'order': 3 } ] }, proxy: { type: 'memory', reader: { type: 'json', root: 'items' } } });
view is grid bind to this store:

Ext.define('AlertScheduler.view.EventTitleGrid', { extend: 'Ext.grid.Panel', alias: 'widget.EventTitleGrid', store: Ext.data.StoreManager.lookup('sid'), columns: [ { text: '', dataIndex: 'name', flex: 1, align: 'center' }, { text: 'Enable', dataIndex: 'enable', width: 60, align: 'center' }, { text: 'Label', dataIndex: 'label', width: 140, align: 'center' }, { text: 'Maxlength', dataIndex: 'maxlength', width: 70, align: 'center' }, { text: 'Order', dataIndex: 'order', width: 60, align: 'center' } ], width: 450, forceFit: true, initComponent: function () { this.callParent(arguments); } });

From what I understand(i am new for Extjs if I was wrong please correct me) store will automatic load into view when view create.
question: how can I filter the store data before it load into view ? (for example I only want to load the data which name = Lisa) is there any method I can filter data in view level (grab all store data to view and filter them before actually load into view),
or can I pass the filter from view to store so store will filter data and return the data that view required ? (in my case I have different view share same store view1 look up data name = 'Lisa' and view2 look up data label = '555...' if the view pass different filter to store, store will return different sets data)

30 Apr 2014, 9:58 AM
For filtering, you don't need to think about view as the view automatically displays that what is in the store. Generally, you call store.filter() (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-filter) to activate filtering.

30 Apr 2014, 10:07 AM
Thank for your reply, but how can I pass filter from view to store? If I have different views share same store, how I can achieve it?

30 Apr 2014, 10:41 AM
What do you mean by
pass filter from view to store?. View is just a table with rows, it has no filter.

30 Apr 2014, 11:07 AM
What do you mean by pass filter from view to store?

. View is just a table with rows, it has no filter.

Sorry I mean when define view we can specify store like
Ext.define('myview', {
store: Ext.data.StoreManager.looup('myStore'), // how can I pass parameter to store so depend on parameter different views can retrieve different sets data from store

if it is no possible to do that , how can I achieve different views bind to same stores but retrieve different sets of data

1 May 2014, 8:51 AM
This way you have only one instance of the store. If this one instance of the store is used by multiple views, the views would always display the same data.

If you want multiple instances to be independent you have to create the store in the views' initComponent where you can pass also filters for initial filtering.