PDA

View Full Version : Unable to load the select value to extjs combobox



GayetriMansingh
26 Nov 2013, 2:52 AM
Hi,
I am loading the combobox field with JSON data.
for example: New, Old, existing .
I have selected Old and saved. the data is getting saved to backend.
I am not able to retrieve the data Old in the combobox on page load.
The other texfield data is populating from backend except combobox.
Please help.

following is the code:



// =====================================================//
//Store for Customer type
//=====================================================//
Ext.define('acquisitionList', {
extend : 'Ext.data.Model',
fields : [ {
name : 'listValueId',
type : 'int'
}, {
name : 'listValueSubCategory',
type : 'string'
} ]
});
var storeAcquisition = Ext.create('Ext.data.Store', {
model : 'acquisitionList',
proxy : {
type : 'ajax',
url : basePath +'salesOrder/CustomerType.json',
reader : {
root : '',
type : 'json'
}
}
});

..................................


{
xtype : 'combobox',
fieldLabel : 'Customer type',
anchor : '90%',
maxLength : 20,
enforceMaxLength : 20,
style : 'margin-left:60px',
vtype : 'alpha',
allowBlank : true,
name : 'lvacquisition',
id : 'lvacquisition',
store : storeAcquisition,
displayField : 'listValueSubCategory',
valueField : 'listValueId',
emptyText : 'Select a Type'
},

scottmartin
26 Nov 2013, 7:39 AM
You have a blank root? what does your return json look like?

GayetriMansingh
26 Nov 2013, 7:25 PM
Hi,
Following is the JSON:
[
{
"listValueId": 303,
"listValueCategory": "Account Acquisition ",
"listValueSubCategory": "Old",
},
{
"listValueId": 304,
"listValueCategory": "Account Acquisition ",
"listValueSubCategory": "New",
"listValue": 1,
},
{
"listValueId": 305,
"listValueCategory": "Account Acquisition ",
"listValueSubCategory": "Existing",
"listValue": 2,
},
{
"listValueId": 306,
"listValueCategory": "Account Acquisition ",
"listValueSubCategory": "Returning",
"listValue": 3,
}
]

and in the combobobox the values are Old, New, Existing, Returning.

The values get poplated in drop down.
I can also save the data from combobox to backend. But at the time of retrieval the save value is not populating to the combobox.

Thanks for the help

n_p_5555
26 Nov 2013, 10:47 PM
Hi,

Actually your question makes a bit confusion but i think you are looking for following one.

Get combobox object using this line code.

var combo = Ext.getCmp('lvacquisition');

Say you have server side value in following variable (which is for 'old' ).

var val = 303;

And set this value using following line of code.

combo.setValue(val);

Make one thing sure that before doing this three line of code u must have filled your combo with all values.

GayetriMansingh
26 Nov 2013, 11:01 PM
Hi ,Thanks for the reply.
I have tried like this:

var combo = Ext.getCmp('lvacquisition');
var val = 303;
combo.setValue(val);

on page load the combobox is displaying 303, but the behavior should be dynamic. I should put listValueId and whatever value in database should be displayed.
forexample..the vale is existing in db, it should display existing, if value is New in db it should display New in combo and so on.

thanks

n_p_5555
26 Nov 2013, 11:24 PM
Hi,

Please make sure that your combobox is already filled with your all values after that this three line code is getting executed.

OR

try this

add this listener in you combo

listeners: {
boxready: function () {
var val = 303;
this.setValue(val, true);
}
}

Note : I assume that you already have value in variable val from server side by using Ajax call or some thing else.

GayetriMansingh
26 Nov 2013, 11:31 PM
Hi,
I tried the same..
var combo = Ext.getCmp('lvacquisition');
var val = 303;
combo.setValue(val, true);

but it is still displaying 303..do I really need to hard code val=303..or some id should be there ?

scottmartin
27 Nov 2013, 11:54 AM
You should not have to manually set the value.

See if this example will point you in the right direction:

1s0