We had to create a column that gave us the difference (in percentage) of two columns. We had to refer to the entire data model to get the result we needed. The great thing about this is that the column data changes as you make changes to the dependant columns.
Solution for dynamic calculating columns :
code for structure (line):
{get:function(inRow){ return getCalcCol.apply( this, [inRow,'col_name1','col_name_2','per_chg' ] ); }, formatter: formatPercent, constraint: {places: 2, type:'percent'}, name:"% Chg", width: "6" },
code for functions
formatPercent = function(inDatum) {
return isNaN(inDatum) ? '...' : dojo.number.format(inDatum, this.constraint);
}
getCalcCol = function( inRow,col1,col2,oper ){
if ( this.grid.model.data[inRow] ){
v1 = this.grid.model.data[inRow][col1];
v2 = this.grid.model.data[inRow][col2];
if ( oper == 'multiply' )
return v1*v2;
else if ( oper == 'per_chg' && v1>0 && v2>0)
return (v2-v1)/v1;
} else {
return "...";
}
};
Credit to: Kiyu Gabriel kiyu(a)iwe.cc
