PDA

View Full Version : Two combos with shared store



Spenna
6 Jan 2012, 12:50 AM
Hi all.

I have a form with two combos that both share the same store, and this store is filtered remotely based on other items in the form. Basically the values in the two combos are never the same. Now, the issue i'm having is that when i have selected a value in the first combo and triggers store.load with new filter (to populate the second combo) the first combos value is changed from the name to the id. I take this is because the underlying record that is used for rendering is removed from the store.
So - how to i use the same store twice on the same form?
I've tried cloning the store using Ext.clone(Ext.getStore('MyStore')) to have a separate instance for each combo, but this does not work, and i'm reluctant to create a separate store just to work around this issue.

Any suggestions?

Spenna
6 Jan 2012, 1:11 AM
Found a working solution. On the second combo i explicitly create a new instance of the store using Ext.create i.e:


// first combo
{
xtype: 'combo',
store: 'MyStore'
}
// second combo, explicitly creating new instance
{
xtype: 'combo',
store: Ext.create('MyStore')
}

skirtle
6 Jan 2012, 2:17 AM
The way I'd do this is to subclass store:


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

...
});

Then you can do this:


{
xtype: 'combo',
store: {type: 'mystore'}
}

This will create a new instance of MyStore each time. I tend to avoid storeId, sharing stores has too many potential pitfalls.

Spenna
6 Jan 2012, 2:53 AM
Nice one, thanks!