PDA

View Full Version : [AUTO SOLVED !]Add dynamic Columns with renderer into a Grid



francois.thareau
6 Jul 2010, 6:13 AM
i have a problem to add columns into a GRID:

src :

for (i = 0; i < nb_poste; i = i + 1) {
var tmp_name = 'etp_prev_' + i ;
//* test pour correction bug
var tmp_name2 = 'cout_prev_' + i ;
// ---------------------------------READER
tab.push({
name: tmp_name,
type: 'float'
},{
name: tmp_name2,
type: 'float'
});

// ---------------------------------HEADER level 1
tableau.etp.headers.push({
header: 'Nom prénom<br/>intitule',
tooltip: 'intitule de poste very très long',
colspan: 2,
align: 'center'
});

// ---------------------------------COLUMNS LEVEL 2
tableau.etp.columns.push({
header: 'ETP prévisionnel',
tooltip: 'ETP prévisionnel',
width: 75,
sortable: false,
renderer: editable2,
dataIndex: tmp_name
}, {
header: 'Coût prévisionnel',
tooltip: 'Coût prévisionnel',
summaryType: 'sum',
work : (just to detect the bug, thiss row will be deleted)
dataIndex: tmp_name2,
not work : i want add a dynamic column with a renderer, tmp_name is the name of the column
renderer: function(v, params, record){
return eval('record.data.' + tmp_name);
}

the error with the code do not work :

this.ds.fields.get(c) is undefined
chrome://firebug/content/blank.gifvar swfobject=function(){var E="undefi...);Ext.grid.GroupingView.GROUP_ID=1000;

thank you for your help
( i'm french and sorry for my english)

francois.thareau
15 Jul 2010, 5:03 AM
The solution :

redifined a summary function :

Ext.ux.grid.GroupSummary.Calculations['totalCoutPrev'] = function(v, record, field, rowIndex, columnIndex, store){

var tmp = field.substr(field.indexOf('_', (field.length - 5)) + 1, field.length);
var res = 0;//eval(v) ;
res += (tableau.etp.postes[tmp]* eval('record.data.etp_prev_' + tmp));
return res ;
};

modifiate the summaryType and the renderer :

summaryType: 'totalCoutPrev',
dataIndex: tmp_name2,
width: 120,
renderer: function(v, params, record, rowIndex, columnIndex, store){

if (columnIndex != null) {

var tmp = ((columnIndex - 3) / 2) - 1;
if (tmp != null && eval('record.data.etp_prev_' + tmp) != null) {
return arrondir(eval('record.data.etp_prev_' + tmp) * tableau.etp.postes[tmp]);
}
else {
return v;
}
}
}

Animal
15 Jul 2010, 5:07 AM
Why are you using eval?

Animal
15 Jul 2010, 5:09 AM
Get a field's value from a Record by name:



record.get('etp_prev_' + tmp);

francois.thareau
15 Jul 2010, 5:15 AM
It's worked too