Extjs: How to l set value for combobox when loading

comboboxextjs

  1. I am looking for a load listener, that when the combobox is up, load will be called and preform an ajax to the server to take the correct display value for the combobox.
    But, load function is never called.. how can i fix it ?

  2. I want to display a text before the combobox, so i added the attribute fieldLabel: 'Save logs to:'. But the text is not displayed.

Thx,
Yoni

this.log_save_combo = new Ext.form.ComboBox
    ({
        store: ['Device', 'USB1', 'USB2']
        , id: 'cplogs_log_save_combo'
        , name: 'cplogs_log_save_combo'
        , triggerAction:'all'
        , fieldLabel: 'Save logs to:'
        , editable: false
        //, value: "Device"
        , listeners: {
                'load': function(){
                        alert("in load function");
              }
    });

Best Answer

As a general solution to the problem, I've gone with

listeners:{
    scope: this,
    afterRender: this.selectFirstComboItem
}

with

selectFirstComboItem: function(combo) {
    // This will tell us if the combo box has loaded at least once
    if (typeof combo.getStore().lastOptions !== "undefined") {
        // Grab the first value from the store
        combo.setValue(combo.getStore().first().get(combo.valueField));
    }
    else {
        // When the store loads
        combo.getStore().on("load", function(store, items){
            // Grab the first item of the newly loaded data
            combo.setValue(items[0].get(combo.valueField));
        });
    }
}