groupBy and stat functions

Hi, using the groupBy method:

mygrid.groupBy(1,["","#title", “#stat_min”]);

in my grid with date values in the 3rd column, i get NaN as a result.

Does it work only with numbers?

I need to get mins and max of the dates in various groups, is this possible?


Does it work only with numbers?
Yep, it works only with numbers. But you can create custom statistics counter which will work with dates. Please find more information here … s_counters

Ehmm, if i try to define the custom function following your sample:

      var calck=function(){
          var maxdate=0; //set initial
              //here i should put dates comparison
          return maxdate;

and then use:

mygrid.groupBy(1,["","#title", “#stat_mindate”]);

i get:

“a is not a function”   in: dhtmlXGridObject.prototype._b_processing=function(a,ind,rind){…}

Did I miss something?

The previously suggested solution is the one for normal grid’s , it not applicable for groupBy mode.
The next code can be used in groupBy to get min-date ( sample code based on assuming that all dates is in common format )

mygrid._g_stat_mindate = function(c,n,i){
if (!i) c=new Date(9999,1,1);
n = new Date(Date.parse(n));

var res = (n<c?n:c);
res.toString = function(){ return this.getDate()+"/"+(this.getMonth()+1)+"/"+this.getFullYear(); }
return res;

mygrid.groupBy(1,["","#title", “#stat_mindate”]);

Where res.toString line defines format of final text in the grid.
Also, to have above code works correctly, you need to change dhtmlxgrid_group.js
to the

It works, thanks so much!
The result appears in the attached picure.
One last question (i promise :slight_smile: ): is it possible to have the value of the column “Est. Dur.” to be the difference of the previous
2 columns  (24/10/2009 - 15/10/2009)  ?

The code similar to the next can be used to implement such use-case

mygrid.groupBy(…some configuration…)
for (var text in mygrid._groups){
var row = mygrid._groups[text].row;
var start = mygrid.cells3(row,3).getValue();
var end = mygrid.cells3(row,4).getValue();
var diff = some_magic_method(start, end);


Thanks for the hint, however if i do that or even if i do:

mygrid.attachEvent(“onGroup”, function(){
      for (var text in mygrid._groups){

i never reach the alert(text) row. Am i missing something obvious?

Are you calling group-by before or after loading data in grid?
If grid was grouped before data loading, onGroup event occurs when there is no data - so no any group, and code will not be triggered.

You were right, obviously!
However the code breaks at your last line:


just after setting the right value in the 5th column for the first group.
The error it throws is : “this.grid is undefined” at the following line (taken from firebug):

val2){this.cell.innerHTML=val;this.grid.callEvent(“onCellChanged”, […

As fast solution, you can change the code as

row.grid = mygrid;

Thanks a lot, the goal has been reached. I like this grid so much.