-
29 Dec 2010 1:56 AM #1
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 :
My question is, How Can we set the combobox value based on the "rating" data like this?Code:Ext.getCmp('combo_id').setValue('2'); // By the ID
Ex :
I try the last code but it didn't work..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
Could someone help me please?
Thanks in advance..
Berusaha dan Berdoa
-
29 Dec 2010 2:45 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 43
Code:var combo = Ext.getCmp('combo_id'); var rec = combo.findRecord(combo.displayField, 'B'); combo.setValue(rec.get(combo.valueField));
-
30 Dec 2010 12:23 AM #3
Thanks a lot Condor for your reply.
But there is an error like this:
On the other side, If I try it directly from firebug, it works.Code:rec is undefined combo_unit.setValue(rec.get(combo_unit.valueField));
is there something wrong?
Thanks..
Berusaha dan Berdoa
-
30 Dec 2010 12:36 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 43
I assume you forgot to wait for the combobox store to load.
-
30 Dec 2010 1:18 AM #5
Hmm.., I have loaded my combo store before I use the code.
is that a right way?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));
Thanks..
Berusaha dan Berdoa
-
30 Dec 2010 1:34 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 43
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)); } });
-
30 Dec 2010 8:17 PM #7
Oh ya..., I See...
it works now...
Thanks a lot Condor...
Berusaha dan Berdoa
Similar Threads
-
how to set the combobox value
By barbara1712 in forum Ext 3.x: Help & DiscussionReplies: 6Last Post: 22 Jan 2010, 12:59 AM -
lastSelectionText not being set in combobox, while combobox is in Grid
By Bakul in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 7 Oct 2009, 12:22 PM -
set the value in combobox
By ByteLess in forum Ext 2.x: Help & DiscussionReplies: 8Last Post: 13 Jun 2009, 9:47 AM -
[Solved] Load a ComboBox, Load a Datastore and set the combobox value with ds data
By pouniok in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 11 May 2009, 2:00 AM -
How to set value to a combobox?
By sunphy in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 12 Aug 2008, 11:56 AM


Reply With Quote