Add Subtotal Row for Each Column within a Group
Add Subtotal Row for Each Column within a Group
Hi,
I have a jQuery Datatable 1.10 up: http://jsfiddle.net/968Pn/2/
My question is that I would like to add a new row for each group to show the subtotal of each item column under the same group.
What makes me headache is that I find it difficult to detect which of the cells are currently hidden in the table, and so when displaying the subtotal, the sums are not displaying under the correct column.
I know there is a similar example which shows the sums in the footer, but that is for the grand total of all the records. What I would prefer in my case is to find out the subtotal of each group, and then show it under the group.
I'm still new to jQuery, and so hope that there would be anyone that can help me. Thank you!
Answers
This may help you (although it doesn't show "under" the groups), http://www.datatables.net/forums/discussion/20844/rowgroup-sum-and-total#latest
Hi Mike,
Oh great! Thanks for the link! It gives me some sort of solution. It doesn't have to be "under" the group, as long as the subtotal row can be differentiated from the normal data rows.
I have updated my script here: http://jsfiddle.net/968Pn/6/
However, another issue is that for the solution, I have to hard-code the colspan value of the group title in the jQuery code (line 48), which I think is not flexible enough, in case the user has the flexibility to enable/disable some columns (e.g. using ColVis plugin).