PDA

View Full Version : One Store Multiple views



oracle.cons.tr
27 Feb 2014, 12:11 PM
Hi i use same store instance in a combo and and in a grid.
when i apply filter to combo grid also filters which is the natural behavior.

Is there a way to apply the filter combo one and let the grid appear as unchanged.
I open the combo in a modal window and after selecting something i am done with it.
But when typing on the combo the grid at the background also changes which doesn't
feels very comfortable.

Btw i donat want to duplicate the data and copy to another store and etc...

Thanks

scottmartin
27 Feb 2014, 5:23 PM
You can access multiple store instances using an alias



Ext.define('MyStore', {
extend: 'Ext.data.Store',

fields: ['state', 'abbr', 'name'],

alias: 'store.mystore',

data: [{
"state": "AL",
"abbr": "BIR",
"name": "Birmingham"
}, {
"state": "AL",
"abbr": "BLU",
"name": "Blue Springs"
}, {
"state": "AK",
"abbr": "KOD",
"name": "Kodiak"
}, {
"state": "AK",
"abbr": "NOP",
"name": "North Pole"
},{
"state": "AZ",
"abbr": "FLG",
"name": "Flagstaff"
}, {
"state": "AZ",
"abbr": "PAV",
"name": "Paradise Valley"
}],

proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.onReady(function() {

Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Filtered Cities',
store: {
type: 'mystore'
},
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners: {
beforequery: function(qe, eOpts) {
qe.combo.store.clearFilter(true);

qe.combo.store.filter(function(record) {
var value = record.get('abbr');
return (value == 'KOD' || value == 'PAV');
});
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Grid',
store: {
type: 'mystore'
},
columns: [{
header: 'State',
dataIndex: 'state'
}, {
header: 'Abbr',
dataIndex: 'abbr',
flex: 1
}, {
header: 'Name',
dataIndex: 'name'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()

});


});

oracle.cons.tr
28 Feb 2014, 4:20 AM
Thanks,
But i have no trouble with accessing the store. I ask if it is possible to filter the store
that is binded to two different views and filtering only affect one view

scottmartin
28 Feb 2014, 5:22 AM
My statement should have read:

You can access multiple store instances using an alias

Did you run my app? the combo is filtered on drop down, but the grid remains unfiltered.

You can paste the code in our fiddle and see:
https://fiddle.sencha.com/#home

oracle.cons.tr
28 Feb 2014, 6:19 AM
Sorry i got it all wrong. Your suggestion does exactly what i need. But i couldnt get it. Before your solution i was binding the store what does this type: variable do exactly?
Thanks

scottmartin
28 Feb 2014, 8:32 AM
It basically creates a generic entry in the StoreManager and this is cloned as needed.
The key is the alias in the store define, then use type create a new instance when needed.

You can also also create a storeId for this entry



store: {
type: 'mystore', // new instance
storeId: 'store-one'
},


// check instances


console.log(Ext.data.StoreManager);
console.log(grid1.getStore());


// result of StoreManager (generic and named)


keys: Array[2]
0: "ext-empty-store"
1: "store-one"