PDA

View Full Version : Reusing same Store in different Combo fields



bkcharan
29 Apr 2013, 10:04 PM
Hello Friends
I have a store that is commonly referenced in several part of the applications. I would like to reuse this store in multiple combo fields by filtering them by the TYPE field in the store.

Here is the code I started, but doesn't seem to work. Any ideas on how to go about doing this? I hope there is someway to accomplish this without having to recreate multiple stores. Please help. Thanks!



xtype: 'combo',
fieldLabel: 'Status Type',
//store: 'References', // this will display all records
listeners: {
afterrender: function() { // Apparently this idea doesn't work :(
var store = Ext.StoreMgr.lookup('References');
store.filterBy(function(record) {
if (record.data.referenceType == 'Status') {
return true;
}
return false;
});
this.bindStore(v);
}
},

slemmon
1 May 2013, 1:56 PM
If you're looking to use the same store 'type', but not the same store 'instance' for each combobox you can first define your store and include an alias of store.references.



Ext.define('MyApp.store.References', {
extend: 'Ext.data.Store',
, alias: 'store.references'

// the rest of the store config
});


Then when you instantiate your combobox you can give a store config like:



store: {
type: 'references'
// any instance config overrides you want to pass in
}


Now you can filter combobox A's store without affecting combobox B; combo.getStore().filter();

bkcharan
1 May 2013, 10:34 PM
It worked perfect! Thanks very much