ashhad
ashhad

Reputation: 173

Set a default value of Combo box

I m trying to set a default value of combo box which is using store. I have tried value, defaultValue and have tried afterrender but nothing seem to work. Did anyone come across with the same problem? Any help would be appreciated.

Upvotes: 0

Views: 4153

Answers (2)

Yasuyuki  Uno
Yasuyuki Uno

Reputation: 2547

Try to set default value after load store.

YourComboBox.setValue('default value');

https://fiddle.sencha.com/#fiddle/16q4

Upvotes: 0

Kld
Kld

Reputation: 7068

// 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"}
    ]
});


Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose State',
    store: states,
    queryMode: 'local',
    displayField: 'name',
    valueField: 'abbr',
    value: 'AL', // the value should be an existing  store's valueField
    renderTo: Ext.getBody()
});

Upvotes: 4

Related Questions