PDA

View Full Version : combo in grid



raj_plays
23 Aug 2010, 6:11 AM
Hi,
I have a GridPanel with an editor plugin.
One of the columns is a combo.
Its name is a string and value is an int.
When a record is saved, the int value goes into the DB.
Now, whan I have to display them, I get the int value, convert it to its corresponding string(name) and display it.
The problem is when a user tries to edit the value, it sends the name (a string) instead of the value (an int) to the server side.

Any ideas about how to show the name but send its value??



var Record3 = Ext.data.Record.create([
{name: 'weather', type: 'string', convert: function(value, data){
return showGroup(value);
}}
]);

var c = new Ext.form.ComboBox({
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:new Ext.data.SimpleStore({
fields:['value', 'name'],
data: [[0, 'None'], [1, 'Div'], [2, 'URL link']]
}),
mode: 'local',
displayField: 'name',
valueField: 'value'
});


var ColModel = new Ext.grid.ColumnModel([

{header: "Weather", width: 70, dataIndex: "weather", sortable: true, editor: c, align: 'left'}

]);


and the convert function:

function showGroup(value)
{
switch(value)
{
case'0':
return'None';
break;
case'1':
return'Div';
break;
case'2':
return'URL';
}
}

Condor
23 Aug 2010, 6:40 AM
Don't use showGroup as the field convert function! Instead, use it as the column renderer.

raj_plays
23 Aug 2010, 11:30 AM
Simple and sweet.
Thanks, Condor