View Full Version : How to load array value in combo in extjs4.1 using xtype:combo

25 Feb 2013, 5:37 AM
can anybody tell how to load array value in using xtype:combo and give example in extjs4.1


25 Feb 2013, 7:51 AM
Hi vijay,

See this sample code -

var states = Ext.create('Ext.data.ArrayStore', {
fields: ['abbr', 'state'],
data :[['1', 'hello'],['2', 'hi'],['3', 'bye']]

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'state',
valueField: 'abbr',
renderTo: Ext.getBody()

25 Feb 2013, 9:29 PM
Hi My values are coming in for loop.I want to load for loop values can you tell how to do.How to push my value to store

25 Feb 2013, 9:31 PM
My values are coming form for loop can anybody tell how to push these value in combo

26 Feb 2013, 4:15 AM
var localArrayStore = Ext.create('Ext.data.ArrayStore', {
fields : [
populate the arrayStore variable with the data you are parsing in the for loop and assign it to combo object store.

11 Apr 2013, 9:36 AM
If you can get the back end to populate the value param, then it's easy.

data :[['1', 'hello'],['2', 'hi'],['3', 'bye']]
value : '0' // select "hello" in combo box on render

Alternatively you can do something like this:

value : '<?php echo $myValue ?>',
listeners: {
afterrender: function(combo) {
if (combo.getValue() === '') { combo.setValue(combo.store.getAt('0').raw.label); }
// Set item 0 as default value if one is not being set }

Hope that helps.