Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Gabi ( Flextronics Israel LTD ) on Jun 10, 2008 23:35
open dhtmlx forum
Summing groups ( dhtmlxGrid )

How can i sum each group ?

Basically i want to show an extra row right before the group ends with the totals. ( not in the footer )

Thank you.
Answer posted by Support on Jun 11, 2008 02:36
There is no build in support for such use-case, but something similar can be done with custom code

   mygrid.loadXML("grid.xml",function(){
      for (var a in mygrid._groups){   // for each group
         var id=mygrid.getUID();
         mygrid.addRow(id,["","",a])   // add total row
         mygrid.setRowColor(id,"#FFFFCC")
         mygrid.setRowExcellType(id,"ro")
         mygrid.setColspan(id,0,8);   // 8 - count of columns in grid
         var total=0;
         mygrid.forEachRow(function(id){   //calculate grid total
            if (mygrid.cells(id,this._gIndex).getValue()==a)
               total+=parseFloat(mygrid.cells(id,3).getValue());   // 3 - index of column for calculations
         })
         mygrid.cells(id,0).setValue("Total:"+total);   // set total value
      }
   });
Answer posted by Gabi on Jun 11, 2008 22:47
Thank you for the solution.

However, this is not what I need.

I need the sum to be at the End of each group, not in the End of the grid.

Thank you..
Answer posted by Support on Jun 12, 2008 02:10
Did you check the sample code above?
Actually it creates "total" rows for each group in grid, not the single one for whole grid.

Full sample sent by email.
Answer posted by Faisal Yahya on Jun 18, 2008 23:29
dear support,

do you have a sample where the totals within each group and still remain there even if we change the "group by" for the list?
btw, I am using Prof version of DHTMLX Grid. If you have, can you send it to Faisal.Yahya@ibsrisk.com.


Thanks,

FY
Answer posted by Support on Jun 20, 2008 08:55
There is no such sample ( and possible workaround require pretty complex coding )
The grid doesn't support such feature as "totals for groups", the code above just a possible workaround