PDA

View Full Version : [solved] Question of style



Thomas Triplet
3 Aug 2010, 2:11 PM
Hi, I'm using a modular approach to implement a few components. One of them extends a EditorGridPanel like below. One of the column is based on a Combo, whose actual value (numerical) is different from the value to display (more explicit string). So I need an editor based on that combo and a custom renderer, based on the same combo. I tried to declare the combo within the module, but it doesn't work for some reason. So I came up with having a separate variable, prior to the declaration of the module. It works, but it doesn't feel right :-?
Thanks a lot for any advice :)



var mass_combo = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
mode: 'local',
store: new Ext.data.ArrayStore({
id: 0,
fields: [
'myId',
'displayText'
],
data: [[1, 'High'], [2, 'Medium'], [3, 'Low']]
}), // eo store
valueField: 'myId',
displayField: 'displayText'
}); // eo editor

App.table.Spreadsheet = Ext.extend(Ext.grid.EditorGridPanel, {
//Defaults
title : 'Generic spreasheet'
,iconCls : 'icon-spreadsheet'

// ,intern_mass_combo: new Ext.form.ComboBox({...}) doesn't work as expected

,initComponent : function() {
App.table.Spreadsheet.superclass.initComponent.call(this);
}
columns: [{
header : 'H1'
,dataIndex : 'h1'
,editor : new Ext.form.Checkbox()
}
,{
header : 'H2'
,dataIndex : 'h2'
,editor : mass_combo
,renderer : Ext.util.Format.comboRenderer(mass_combo)
// ,renderer : Ext.util.Format.comboRenderer(this.intern_mass_combo) // doesn't work
}
]
});




Ext.apply(Ext.util.Format, {
comboRenderer: function(combo) {
return function(value) {
var record = combo.findRecord(combo.valueField, value);
return record ? record.get(combo.displayField) : value;
};
} // eo comboRenderer()
}); // eo Ext.apply()

Condor
4 Aug 2010, 12:55 AM
Move the creation of the combobox and the definition of the columns inside the initComponent call.

Thomas Triplet
4 Aug 2010, 7:36 AM
Thanks a lot Condor, that works - and looks - great now!