1. #1
    Sencha User
    Join Date
    May 2010
    Location
    Jakarta - Indonesia
    Posts
    169
    Vote Rating
    0
    yagi is on a distinguished road

      0  

    Default How can we set a combobox value like this ?

    How can we set a combobox value like this ?


    Hi All..

    Actually it is a basic question but I'm still a bit confused of this case.

    Here I have data like this in my database:
    id | rating
    1 | A
    2 | B
    3 | C

    If I try to set the combobox like this, it works..
    Ex :
    Code:
    Ext.getCmp('combo_id').setValue('2');
    // By the ID
    My question is, How Can we set the combobox value based on the "rating" data like this?
    Ex :
    Code:
    Ext.getCmp('combo_id').setValue('B');
    // in the combo list, B should be selected and when I want to save it, the combo will send '2' as the value
    I try the last code but it didn't work..


    Could someone help me please?


    Thanks in advance..
    Berusaha dan Berdoa

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    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:
    var combo = Ext.getCmp('combo_id');
    var rec = combo.findRecord(combo.displayField, 'B');
    combo.setValue(rec.get(combo.valueField));

  3. #3
    Sencha User
    Join Date
    May 2010
    Location
    Jakarta - Indonesia
    Posts
    169
    Vote Rating
    0
    yagi is on a distinguished road

      0  

    Default


    Thanks a lot Condor for your reply.

    But there is an error like this:
    Code:
    rec is undefined
    combo_unit.setValue(rec.get(combo_unit.valueField));
    On the other side, If I try it directly from firebug, it works.

    is there something wrong?


    Thanks..
    Berusaha dan Berdoa

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    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


    I assume you forgot to wait for the combobox store to load.

  5. #5
    Sencha User
    Join Date
    May 2010
    Location
    Jakarta - Indonesia
    Posts
    169
    Vote Rating
    0
    yagi is on a distinguished road

      0  

    Default


    Hmm.., I have loaded my combo store before I use the code.
    Code:
    // render the combo to a panel, and place it to window.
    ...
    var combo_unit = Ext.getCmp('id_unit_value');
    combo_unit.store.removeAll();
    combo_unit.store.load({
    	params: {
    		'idunit': record.idunit
    	}
    })
    	
    var rec = combo_unit.findRecord(combo_unit.displayField, val2[2]);
    console.log(combo_unit.findRecord());
    combo_unit.setValue(rec.get(combo_unit.valueField));
    is that a right way?

    Thanks..
    Berusaha dan Berdoa

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    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, you have to wait for the server to respond (remember that the A in Ajax is from Asynchronous).
    Code:
    combo_unit.store.load({
      params: {
        idunit: record.idunit
      },
      callback: function(){
        var rec = combo_unit.findRecord(combo_unit.displayField, val2[2]);
        console.log(combo_unit.findRecord());
        combo_unit.setValue(rec.get(combo_unit.valueField));
      }
    });

  7. #7
    Sencha User
    Join Date
    May 2010
    Location
    Jakarta - Indonesia
    Posts
    169
    Vote Rating
    0
    yagi is on a distinguished road

      0  

    Default


    Oh ya..., I See...


    it works now...


    Thanks a lot Condor...
    Berusaha dan Berdoa

Similar Threads

  1. how to set the combobox value
    By barbara1712 in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 22 Jan 2010, 12:59 AM
  2. lastSelectionText not being set in combobox, while combobox is in Grid
    By Bakul in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 7 Oct 2009, 12:22 PM
  3. set the value in combobox
    By ByteLess in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 13 Jun 2009, 9:47 AM
  4. Replies: 2
    Last Post: 11 May 2009, 2:00 AM
  5. How to set value to a combobox?
    By sunphy in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 12 Aug 2008, 11:56 AM

Thread Participants: 1