New Statistics Counter for dhtmlxGrid

There are times when I need the value of a column for the last row in a grid for a footer through an XML Document. I successfully created a custom statistics counter, but am reluctant due to potential problems when upgrading to the next dhtmlx version. I think others would find this counter useful, so I’m requesting it to be added to the dhtmlxgrid functionality. The code I wrote is based on the documentation on the grid product and existing functionality. It is as follows:

dhtmlXGridObject.prototype._in_header_stat_last = function(t, i, c) {
var calck = function() {
var summ = 0;
var j = this.rowsBuffer.length - 1;
var v = parseFloat(this._get_cell_value(this.rowsBuffer[j], i));
summ = isNaN(v) ? 0 : v;
return this._maskArr[i] ? this._aplNF(summ, i) : (Math.round(summ * 100) / 100);
}
this._stat_in_header(t, calck, i, c, c);
}

Can you pls tell me wat t(tag) and i(index) stand for?
I looked up this link
docs.dhtmlx.com/doku.php?id=dhtm … s_counters also but still getting errors :frowning:

The counter I need to implement is a function like this:

mygrid2.customGroupFormat=function(name,count){
var tot=mygrid2.groupStat(name,8,“stat_total”);
var serv= mygrid2.groupStat(name,7,“stat_total”);
var serv_pen=(serv/tot)*100;

return name+",    "+Math.round(serv_pen)+"%";
}

How can this be acheived by using your method so that column 10 can display the returning value ?
Pls help!!!

tag - html tag in which counter will be placed
index - index of column in grid, to which it linked

grid._in_header_stat_count=function(tag,index,c){ var calck=function(){ // here you need to place your custom code // index - index of column // this - grid object // ignore other external var return "html string with necessary value"; } this._stat_in_header(tag,calck,index,c); }

Thanks :slight_smile:
But when I am attaching your example to my code before calling loadXML,

mygrid2._in_header_stat_summ=function(tag,index,c){ // shortcut for statistics counter
var calck=function(){ // define the function which will be used for calculations
var summ=0; // set initial counter value
this.forEachRow(function(id){ // for each row
summ+=this.cells(id,index).getValue()*1; // add row_value
})
return summ;
}
this._stat_in_header(tag,calck,index,c); //call default statistics handler processor
}

and calling groupBy in this way

mygrid2.groupBy(0,["#title","","","","","","#stat_total","#stat_summ"]);

It keeps showing me an error in dhtmlx_group.js file line 35 .
How should the counter be connected to groupBy line?
PLS help!!!