PDA

View Full Version : Adding items to combobox



TommyMaintz
3 Apr 2007, 7:18 AM
Hey guys,

This is probably too easy but i can't add an item dynamically to a combobox wich is in mode: 'local' (transformed an existing select).
Im doing it like this atm:


combobox.store.loadData([{id:'someid', avalue:'somevalue'}], true);
does somebody know what the correct way to dynamically add an item to a combobox in local mode?

tryanDLS
3 Apr 2007, 8:55 AM
Using the combo example as a base, you can add a row by doing:

converted.store.insert(50, new Ext.data.Record({value:'XX', text:'Test'}));

TommyMaintz
3 Apr 2007, 7:14 PM
Thanks Ryan!

store.add(new Ext.data.Record({value:'XX', text:'Test'}));

is even more suitable in this situation. thanks for helping me out!

Strock
28 Jun 2007, 11:08 PM
Can you please tell me, how do I auto-select the item I just added to ComboBox as described?

fay
29 Jun 2007, 1:00 AM
Use setValue(). Of course, it depends on how you've set up your combobox.


cbFluidGroups = new Ext.form.ComboBox({
store: dsFluidGroups,
fieldLabel: 'Fluid Groups',
valueField: 'FluidGroupId',
displayField: 'Text',
editable: false,
mode: 'local'
});

// When the FluidGroups store is loaded add a * (All Groups) record and select it.
dsFluidGroups.on('load', function(store, records, options)
{
dsFluidGroups.insert(0, new Ext.data.Record({FluidGroupId:'0', Text:'*'}));
cbFluidGroups.setValue(0);
}, this, {single: true});

Strock
29 Jun 2007, 2:04 AM
Use setValue(). Of course, it depends on how you've set up your combobox.


cbFluidGroups = new Ext.form.ComboBox({
store: dsFluidGroups,
fieldLabel: 'Fluid Groups',
valueField: 'FluidGroupId',
displayField: 'Text',
editable: false,
mode: 'local'
});

// When the FluidGroups store is loaded add a * (All Groups) record and select it.
dsFluidGroups.on('load', function(store, records, options)
{
dsFluidGroups.insert(0, new Ext.data.Record({FluidGroupId:'0', Text:'*'}));
cbFluidGroups.setValue(0);
}, this, {single: true});

Thank you very much, this works. My combo is organised just as you explained )))