Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load default value for a comboBox extjs

how can i load a default value from my json store (remote) into a combobox , i've tried load the store before render the combo , and use setValue() i want my combo to display the first result in the store plz tell me the right way to do this and thanx

like image 548
cranberies Avatar asked Aug 15 '10 20:08

cranberies


1 Answers

You need to set the value property to the value of the first element after the store is loaded

Ext.ns('MyNamespace');

MyNamespace.MyComboBox = Ext.extend(Ext.form.ComboBox, {
  displayField: 'displayValue',
  triggerAction: 'all',
  valueField: 'ID',

  initComponent: function () {
    this.store = new Ext.data.JsonStore({
      url: 'url',
      baseParams: {
        //params
      },
      fields: [
        {name:'ID', mapping: 'ID', type: 'int'},
        {name:'displayValue', mapping: 'displayValue', type: 'string'},
      ],
      root: 'root'
    });

    var me = this;
    this.store.on('load',function(store) {
      me.setValue(store.getAt(0).get('ID'));
    })

    MyNamespace.MyComboBox.superclass.initComponent.call(this);

    this.store.load();
  }

});
like image 128
Mchl Avatar answered Sep 21 '22 12:09

Mchl