-
2 Feb 2012 9:02 AM #1
Answered: combobox local store and data - set default value
Answered: combobox local store and data - set default value
Hi -
I have a very simple combobox - I'm creating the store and its data locally since the data set is so small.
-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.Code: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 }],
-
Best Answer Posted by josephkirubakaran
You can use the value config to set default value.
Code:// 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() });
-
2 Feb 2012 9:29 AM #2
You can use the value config to set default value.
Code:// 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() });
-
2 Feb 2012 10:25 AM #3
Thanks for the simple solution. It's working good
Code: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(); } } }],


Reply With Quote