1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    India
    Posts
    94
    Vote Rating
    0
    nikhilkrishnan is on a distinguished road

      0  

    Smile ComboBox : using select () to select the first item from the store.

    ComboBox : using select () to select the first item from the store.


    Hi,

    I need to set the first item from the store as the selected item in the combobox as soon as the form opens .
    Code:
    cro_store=new Ext.data.JsonStore({
                        url:base_root+"php/cce_target_achievement.php",
                        id:'cro_store',
                        totalProperty:'totalCount',
                        root:'qry',
                        fields:['user_id','name'],
                        baseParams:{task:'GET_CRO'}
                    });
                    cro_store.load();
                    cro_combo=new Ext.form.ComboBox({
                        id:'cro_combo',
                        fieldLabel:'CROs',
                        store:cro_store,
                        mode:'remote',
                        typeAhead: true,
                        anchor:'100%',
                        triggerAction: 'all',
                        displayField:'name',
                        valueField:'user_id',
                        emptyText:'CROs'
                    });
    cro_combo.select(0);
    But this shows an error in the firebug

    Code:
    this.view is undefined
    Ext.form.ComboBox=Ext.extend(Ext.form....);Ext.reg("combo",Ext.form.ComboBox);
    I cannot use setValue and selectByValue as the datas are dynamic.

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    No, don't use select() or selectByValue() (I don't even know why these methods are documented as public - you should never use them).

    Instead, use setValue().

    ps. Don't forget that you have to wait for the store to load before you can select the first entry!

  3. #3
    Sencha User
    Join Date
    Dec 2008
    Location
    India
    Posts
    94
    Vote Rating
    0
    nikhilkrishnan is on a distinguished road

      0  

    Wink


    Quote Originally Posted by Condor View Post
    No, don't use select() or selectByValue() (I don't even know why these methods are documented as public - you should never use them).

    Instead, use setValue().

    ps. Don't forget that you have to wait for the store to load before you can select the first entry!
    Thank you for the reply Condor. To use the setValue() method i need to know the values that are currently loaded in the store. But what if the values are dynamic ? I mean what if the values keep changing.

    I just want to select the first value which ever comes first in th store .

    Thank you...

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Code:
    cro_store.load({
      callback: function(){
        cro_combo.setValue(cro_store.getAt(0).get('user_id'));
      }
    });

  5. #5
    Sencha User
    Join Date
    Dec 2008
    Location
    India
    Posts
    94
    Vote Rating
    0
    nikhilkrishnan is on a distinguished road

      0  

    Default


    Thank you. I think i need to read the docs a lot. Its working

Similar Threads

  1. by default select first item for combobox having array as store
    By santoshsatav in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 2 Dec 2010, 10:39 AM
  2. [SOLVED] I cant select the item on Combobox
    By Jamiroquai in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 4 Nov 2008, 7:11 AM
  3. Select automatically one item in a ComboBox
    By junkzilla in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 4 Aug 2008, 9:05 PM
  4. ComboBox select first Item
    By pauleee in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 29 May 2008, 5:03 AM
  5. ComboBox select item fact ....
    By armandoxxx in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 14 May 2008, 4:15 AM

Thread Participants: 1

Tags for this Thread