Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto select (show) the first value of combobox in Ext Js?

This is my combobox

{
    xtype: 'combo', 
    fieldLabel: LANG.LOGIN_LANG,
    id : 'lang', 
    store: [
        ['tr','Türkçe'],
        ['ru','Русский'],
        ['en','English']
    ],
    mode: 'local',
    triggerAction: 'all',
    selectOnFocus:true
},
like image 236
ilhan Avatar asked Jul 15 '11 07:07

ilhan


2 Answers

Generally, when I want to select the first value of a store, I use this methods:

xtype: 'combo', 
fieldLabel: 'prov',
id : 'lang', 
store:[['tr','Türkçe'],['ru','Русский'],['en','English']],
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
listeners: {
    afterrender: function(combo) {
        var recordSelected = combo.getStore().getAt(0);                     
        combo.setValue(recordSelected.get('field1'));
    }
}
like image 166
M-S Avatar answered Oct 24 '22 22:10

M-S


{
  xtype: 'combo', 
  fieldLabel: LANG.LOGIN_LANG,
  id : 'lang', 
  store:[['tr','Türkçe'],['ru','Русский'],['en','English']],
  mode: 'local',
  triggerAction: 'all',
  value: 'tr',
  selectOnFocus:true
},

For remote comboboxes you need to plug into store's load event to select the value after store is loaded.

like image 43
Mchl Avatar answered Oct 25 '22 00:10

Mchl