Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a combobox value in ExtJs?

Tags:

extjs

extjs3

I am trying to simply select an item in the dropdown list after it has been loaded into a store. This does not work:

Ext.getCmp('ddlModel').setValue(aircraftStore.getAt(0).data.ModelTypeCode);

This throws an exception:

Ext.getCmp('ddlModel').selectByValue(aircraftStore.getAt(0).data.ModelTypeCode);

Here is the exception: 'this.view' is null or not an object

Anyone know how to do this in ExtJs?

like image 874
Greg Finzer Avatar asked Jun 12 '12 15:06

Greg Finzer


2 Answers

I created a function to set the value of the combo box in ExtJs:

function ComboSetter(comboBox, value) {
    var store = comboBox.store;
    var valueField = comboBox.valueField;
    var displayField = comboBox.displayField;

    var recordNumber = store.findExact(valueField, value, 0);

    if (recordNumber == -1)
        return -1;

    var displayValue = store.getAt(recordNumber).data[displayField];
    comboBox.setValue(value);
    comboBox.setRawValue(displayValue);
    comboBox.selectedIndex = recordNumber;
    return recordNumber;
}
like image 119
Greg Finzer Avatar answered Nov 17 '22 00:11

Greg Finzer


Ext.getCmp('ddlModel').select(aircraftStore.getAt(0));

like image 31
JohnnyHK Avatar answered Nov 17 '22 01:11

JohnnyHK