PDA

View Full Version : combobox local store and data - set default value



qt4x11
2 Feb 2012, 9:02 AM
Hi -

I have a very simple combobox - I'm creating the store and its data locally since the data set is so small.


items : [{
xtype : 'combo',
fieldLabel : 'Station Closed Filter',
labelAlign : 'left',
store : new Ext.data.SimpleStore({
data : [[0, 'SHOW OPEN AND CLOSED STATIONS'], [1, 'SHOW OPEN STATIONS'],
[2, 'SHOW CLOSED STATIONS']],
id : 0,
fields : ['value', 'text']
}),
valueField : 'value',
displayField : 'text',
triggerAction : 'all',
editable : false,
name : 'closedStatus',
itemId : 'stationStatusReportClosedStatus',
flex : 1
}],


-is there a way to set default value to this combo without having to redo how I'm declaring it as an item in a form, and creating the store outside of the combo? Thanks.

josephkirubakaran
2 Feb 2012, 9:29 AM
You can use the value config to set default value.


// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
value:'AZ',
renderTo: Ext.getBody()
});

qt4x11
2 Feb 2012, 10:25 AM
Thanks for the simple solution. It's working good


items : [{
xtype : 'combo',
fieldLabel : 'Station Closed Filter',
labelAlign : 'left',
store : new Ext.data.SimpleStore({
data : [[0, 'SHOW OPEN AND CLOSED STATIONS'],
[1, 'SHOW OPEN STATIONS'],
[2, 'SHOW CLOSED STATIONS']],
id : 0,
fields : ['value', 'text']
}),
valueField : 'value',
value: 0,
displayField : 'text',
triggerAction : 'all',
editable : false,
name : 'closedStatus',
itemId : 'stationStatusReportClosedStatus',
flex : 1,
listeners : {
'select' : function(combo, record) {
// we can get the selected value using getValue()
closedStatusSelectedID = this.getValue();
}
}
}],