PDA

View Full Version : Not able to populate combo box label



saurabhgupta
5 Jul 2013, 12:43 AM
Hello

I am using Extjs 4.2 and i have combo box field is my page . when i am updating this page so i need to show the selected value in combo box . if i used static data so it will work properly but when i am loading data from database then data is coming but it is displaying the value not the label for selected combo box . i have done the work around by using the select method of combo box but i need to iterate the store for getting the selected value because in my store value is not starting from 1 but it is starting from 100 and select method of combo box use the index for list, below is the code you can check but this is not working for multiple combo box.

var specilizationComboBox = Ext.getCmp("doctorMasterVO.specilizationFkId");
var specilizationValue=0;
specilizationStore.each(function(record){
if(record.get('value') != dataRead.dataVO.doctorMasterVO.specilizationFkId){
specilizationValue = specilizationValue+1;
}else{
return false;
}
});
specilizationComboBox.select(specilizationComboBox.store.data.items[specilizationValue]);

please tell me their is any other way to do this because iterate the whole store is not a good idea.

saurabhgupta
8 Jul 2013, 4:49 AM
I find the answer it is given below.

Basicly what you want to do is something like this:

var myId = dataRead.dataVO.doctorMasterVO.specilizationFkId;var record = store.findRecord("id", myId);specilizationComboBox.select(record);Where "id" is the name of the field you are trying to find a match for in your store. Note that myRecord could be null if the record is not there or if the store is not properly loaded.
To make sure the store is loaded you could execute the code above in a load handler:

specilizationComboBox.getStore().load({ scope: this, callback: function(records, operation, success) { //code goes here }});