Custom Group Format for one column in grid


For one of the columns in a ‘grouped’ grid I want to show information which does not depend on value in that column. So I don’t want to use something like #title or #stat_max but instead ‘#my own calculation’.

Please can you tell me if there is any way of doing that using forEachRowInGroup function? An example would be useful.



You may try to use the customGroupFormat method to redefine the text of group-row: … grouping&s[]=customGroupFormat#math_operations_in_group-by_mode

Or you may try to create your own custom calculation.
Here is the examples of the basic values:

dhtmlXGridObject.prototype._g_stat_total=function(c,n,i){ return c+n; } dhtmlXGridObject.prototype._g_stat_min=function(c,n,i){ if (!i) c=Infinity; return Math.min(c,n); } dhtmlXGridObject.prototype._g_stat_max=function(c,n,i){ if (!i) c=-Infinity; return Math.max(c,n); } dhtmlXGridObject.prototype._g_stat_average=function(c,n,i){ return (c*i+n)/(i+1); } dhtmlXGridObject.prototype._g_stat_count=function(c,n,i){ return c++; }

Hi Sematik

Thanks very much for this info. Please can you tell me what the variable c,n,i represent. I don’t want to guess.


One other question. Once I’ve created the function, how do I call it from my code?



your custom shortcut can be called in a second parameter of groupBy() method.
For example:


Thanks very much Sematik for this info.

Please could you also tell me what the variables c,n,i mean in this case.

Also does this function get called every time there is a change in one of the rows in the group?


Hi Sematik I tried doing what you suggested but it doesn’t seem to work. This is my function.

            return 'ABC';

I then called it as part of the second parameter in the groupBy as follows:


but nothing appeared in that particular column. I then commented out the prototype function but left the #test_group in the groupBy and the system didn’t complain. This suggests that if it finds anything other than the pre-defined functions it ignores it.

By the way I’m currently on Version 3.0 Pro.

Please can you tell me what I might be doing wrong.


group stat name should begin with “stat”.
So for your code:

dhtmlXGridObject.prototype._g_stat_test_group=function(c,n,i) { return 'ABC'; }

mygrid._g_stat_test_group = function (tag, index, c) { return "ABC"; };

Hi Sematik

Thanks for the info but I worked that out as well. But it still doesn’t help me because I want to return the total value for all rows for a ‘hidden’ column. However I don’t have access to the row id as the Group Stats are being created so I’m still stuck. Any ideas on how I can access other cells from the rows in that Group?

I’ve looked at forEachRowInGroup function but that requires a group ‘name’ which I also don’t have access to whilst the Stats are being built.

Please help.


Hi Sematik

Please can you show me an example of how forEachRowInGroup function can be used to set the Group Header Row. Perhaps once I understand that then I will be able to work forward.



using the custom shortcut:
mygrid._g_stat_test_group = function (tag, index, c) {
return “ABC”;

tag - the number displaying in the group header (the final result of the math).
index - the value of a current cell (iterating through all rows)
c - counter of the rows in the group.

So, for example, to calculate the sum of the values in the group you need:

dhtmlXGridObject.prototype._g_stat_total=function(tag, index, c){ return tag+index; }

Hi Sematik

Thank you for explaining what each of the variables are. That was very useful.

I’m trying to find a way of using the rest of the row’s information in calculating the Group Header line. Please will you give me an example of how forEachRowInGroup function can be used to set the Group Header line.



Using the forEachRowInGroup() method allows to operate withe rows in the group.
The method should be called from a customGroupFormat function.

mygrid.customGroupFormat=function(name,count){ mygrid.forEachRowInGroup(name,function(id){ console.log(name) // name of the group console.log(id) // row id var val=mygrid.cells(id,4).getValue() console.log(val) // value of a needed cell }); return name+", some logic"+mygrid.groupStat(name,3,"stat_test_group"); }

Thanks Sematik…that is EXACTLY what I needed. I can now use the rest of the information in the Group’s rows to build the Group Header.

Very NICE.


Hi Sematik, Happy New Year

Please may I re-open this topic again. I am still working with V3.0 Prof. I now have a more complex requirement. My grid data consists of rows of bookings for a catering company. Each row shows the date of the booking and the Client Name + a hidden column showing the number of diners. The remaining are a variable number of columns depending on the Cooking Locations that exist during that period. Any one booking can only be allocated to one Cooking Location. So in a single row:

  • the Date column is always filled in
  • the Client Name is always filled in.
  • the hidden column of number of diners is always filled in
  • then out of the remaining columns which represent Cooking Locations all the columns are blank EXCEPT for one which contains some ‘data’ and represents the Cooking Location for that booking.

I want to Group on the Date column but for each Group I want to show the total of diners from the hidden column for the appropriate Cooking Location.

Here is some sample data: = hidden column

Date | Name | Diners | Ckg Loc A | Ckg Loc B
13/1/18 | Client A | <20> | data |
13/1/18 | Client B | <25> | data |
13/1/18 | Client C | <10> | | data

So in my group header I want to show a value of 45 under Ckg Loc A and a value of 10 under Ckg Loc B.

Please can you tell me if this is at all possible and if it is then how I would code it.

Many thanks for your help.

The same approach
You may use the forEachRowInGroup to iterate through the rows in your group and get the required values using the getValue() method.

myGrid.customGroupFormat=function(name,count){ var val; var sum=0; myGrid.forEachRowInGroup(name,function(id){ val=myGrid.cells(id,2).getValue(); sum=sum+parseInt(val); }); return name+", sum="+sum; }

Thanks very much for your response Sematik. What you are suggesting will work for the column containing the #title. However I want to put the number as a #stat in the appropriate column.

You may use the in-built math: … uiltinmath

Hi Sematik, many thanks for your response.

Unfortunately the inbuilt #stat functions don’t have the facility to iterate through each row in the group and use ‘other’ fields of that row before returning a value.

I don’t know whether this is possible but if in the future you could allow for the inbuilt #stat functions to iterate through each row in the group and use ‘other’ fields of that row BEFORE returning a value then I would be able to achieve what I need.

I have changed my apps design so that I can use one of the inbuilt #stat functions for the moment but it is not a perfect situation.

Thanks anyway for all your continued help here.

is it?