DevX
DevX

Reputation: 510

How to select a value from combo box in Ext JS Grid

I have an EXT JS grid which contains a column having a combobox.

enter image description here

I want to select a value in this dropdown using javascript, I tried below snippet but it didn't work.

var comp = Ext.getCmp('grid-accident-voilation'); comp.store.getAt(0).data['c1'].setValue('1');

[EDIT : Browser Console Log ]

enter image description here

Upvotes: 2

Views: 2647

Answers (2)

Trevor Karjanis
Trevor Karjanis

Reputation: 1724

The setValue method must be called on the combobox. http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.ComboBox-method-setValue

The combobox is required to be configured with a field on the items in the store that are each item's value. If you simply want to select the first available option, get the first item from the store and set its value on the combobox.

var combobox = Ext.getCmp('grid-accident-voilation');
var firstItem = combobox.getStore().getAt(0);
// Optionally, get the value field programmatically.
var valueField = combobox.getInitialConfig('valueField');
combobox.setValue(firstItem.get(valueField));

Upvotes: 2

shadowfox
shadowfox

Reputation: 581

Query for the combobox and use myComboBox.setValue(1).

refer:"ComboBox-method-setValue"

Upvotes: 1

Related Questions