Thursday, August 11, 2011

ExtJS (2.2.1): select item on a ComboBox Programmatically


//The store's data definition must have at least a data.id field defined  
set_combobox_value_from_store = function (combobox, valueField, value) {
//Get a reference to the combobox's underlying store
var store = combobox.getStore();
store.load({
    callback: function () {
        //Find item index in store
        var index = store.find(valueField, value, false);
        if (index < 0) return;
        //Get model data id
        var dataId = store.getAt(index).data.Id;
        //Set combobox value and fire OnSelect event
        combobox.setValue(dataId);
    }
});

watch out the change I made on the last line from que reference link:
// before
combobox.setValueAndFireSelect(dataId); // throws setValueAndFireSelect methos doesn''t exist
// value
combobox.setValue(dataId);

reference:
http://www.humbug.in/stackoverflow/es/extjs-combobox-despues-de-reload-tienda-dont-valor-de-conjunto-3781767.html

No comments: