adding a Row-Total Column?
adding a Row-Total Column?
Hi all,
Is there a way to add a final column to a table so that it shows the sum of values foreach row? The "footer" functions work beautifully, and I'm thinking that people like to add their rows as well as their columns. Is there a good way to do this?
This seems like an obvious sort of application, but I don't see it addressed anywhere.
Any ideas?
Thanks,
Ken
Is there a way to add a final column to a table so that it shows the sum of values foreach row? The "footer" functions work beautifully, and I'm thinking that people like to add their rows as well as their columns. Is there a good way to do this?
This seems like an obvious sort of application, but I don't see it addressed anywhere.
Any ideas?
Thanks,
Ken
This discussion has been closed.
Replies
If you want to do it on the client-side, then you could use fnRowCallback to do basically the same as the footer callback: http://datatables.net/usage/callbacks#fnRowCallback
Allan
Can two callbacks be used together? Can I call both the fnRowCallback and the fnFooterCallback? If so, where is that sort of syntax documented?
Thanks! This stuff is great!
Ken
Yes indeed they can be used together - just like all the other DataTables options. It's just a Javascript object, so it would be something like:
[code]
$('#example').dataTable( {
"fnDrawCallback": function (...) { ... },
"fnRowCallback": function (...) { ... }
} )
[/code]
Allan
Ken
My final row contains totals but I want it to remain at the bottom and not be sortable.
I can't find anything in the examples that shows how to do this?
Thanks
Add something like this in your table html
[code]
Total
1000
[/code]
dataTables 1.8 support many rows in the footer section.
Can I please get a working example of Rows summed.
J
Allan
Thanks a lot for your suggestion of using for total.
It did the trick.
--- Vineet
Ricardo
I'm using fnFooterCallback to generate Complete Totals and (Page Totals) at the bottom of my columns.
I'm also using Grouping for the second column in the table, with hiding set to true for that column.
This was working fine when the first column with a Total was the first column following the grouped hidden column. (4 columns with totals overall).
This also worked fine when I turned hiding off for that column.
When I add three more columns WITHOUT totals, just before the first totaled column, with hiding set to false for grouping, EVERYTHING still looks great.
NOW HERE'S THE WEIRD PART:
If I then enable hiding, at this point, the first totaled column gets duplicated into the newly added column immediately before it.
Examples ALL with Grouping:
[With Col1 hidden] - Works Great!
Col0 - (Col1) - Col2/Tot2 - Col3/Tot3 - Col4/Tot4 - Col5/Tot5
[With None hidden] - Works Great!
Col0 - Col1 - Col2/Tot2 - Col3/Tot3 - Col4/Tot4 - Col5/Tot5
[With None hidden and added columns] - Works Great!
Col0 - Col1 - Col2 - Col3 - Col4 - Col5/Tot5 - Col6/Tot6 - Col7/Tot7 - Col8/Tot8
[With Col1 hidden and added columns] -
Breaks! Duplicates first totaled column onto preceeding column
Col0 - (Col1) - Col2 - Col3 - Col4/Tot5 - Col5/Tot5 - Col6/Tot6 - Col7/Tot7 - Col8/Tot8
Anyone get an epiphany looking at this pattern???
I've been scouring the code and can't for the life of me figure out why this is happening.
Joel - Any help VERY APPRECIATED!
Apparently the fnFooterCallback is getting executed 3 times before initial display. The first time it appears to execute before the Grouping and the column hiding takes place causing there to be one more footer column than anticipated so the footer values are offset to the left.
Then it executes again after the Grouping and Column hiding has taken place and overwrites the previous footer values. But of course the first one does get over written because it was off set to the previous column that is not supposed to have a footer value.
Then a third time it is executed.
Again, I don't know why DataTables is executing the code three times.
So, anyway, the solve is simply to use jquery to wipe out all the footer totals whenever the fnFooterCallback function is executed.
Just thought I'd share.
Jz.