PDA

View Full Version : Dynamically change the store of a combo



pcr
5 Mar 2010, 4:45 AM
Hi, I have the following question:

I have a form with 2 combo's. If the user select a value in the first Combo (Combo1) the store connected to the second combo (Combo1) should be changed before the user select this second combo. Here is a snippet of my form:


}, {
xtype: 'combo',
id: 'Combo1',
fieldLabel: 'Label1',
name: 'Name1',
store: DataStore1,
mode: 'remote',
displayField: 'Field1',
allowBlank: false,
valueField: 'Id',
hiddenId: 'Id',
hiddenName: 'FieldId1',
width: 160,
triggerAction: 'all',
listeners:{
select:{
fn:function(combo, value) {
//
// Depending on the selected value in Combo1
// Change the store DataStore2 to DataStore3 in next combo
//
}
}
}
}, {
xtype: 'combo',
id: 'Combo2',
hidden: false,
fieldLabel: 'Label2',
name: 'Name2',
store: DataStore2,
mode: 'remote',
displayField: 'Field2',
allowBlank: true,
valueField: 'Id',
hiddenId: 'Id',
hiddenName: 'FieldId2',
width: 160,
triggerAction: 'all'
}, {


Is this possible? Can anybody help me how to do this??

Zdeno
5 Mar 2010, 7:12 AM
Why you want to change store? Whats about to change store baseParams? It isnt better way?

pcr
5 Mar 2010, 1:50 PM
To change the store is (of course) part of the applicationdesign. Its not simply change parameters. Now I have solve this by but the different combo's (with their stores) in the form. On select I enable 1 combo and hide the other. The trouble with this solution is that the combo's all have their own position.

Is it possible to put some combo's at the same position in the form. That would work.

Anybody can help??

fay
6 Mar 2010, 3:18 AM
Why not something like:


function changeStore(newStore)
{
var ds = Ext.getCmp('Combo2').getStore();
ds.removeAll();
ds.add(newStore.getRange());
}
Create Combo2 with an empty store, create and load your other stores and use changeStore to update the combo's.

Tbh, there must be an easier way than this to do it - especially with loadData.

pcr
6 Mar 2010, 5:12 AM
Hi, Thanks for your tips on this issue. I solved the problem myself. I create a new combo with a store which is filled with data. A special backend sends the right data to this new store with the right data by sending a parameter.

thanks