sum and avg in footer and show/hide columns not working
sum and avg in footer and show/hide columns not working
Misiu
Posts: 68Questions: 4Answers: 2
Hi to all, especially to author, really great work!
I am trying to use in specific scenario:
I have 2 tables on my page, both will have data coming from ajax request.
In last column I have button (image) that allows user to move that row from one table to another. Of course when I refresh data with AJAX it will reset, but that's OK :)
Next thing: how to calculate sum and average in footer so that every time I add/remove row it will recalculate?
Something like in this YUI2 example: http://mattparker.github.com/datatable/colstats.html
Enough of what I want, here is what I have :)
My code is available at: http://live.datatables.net/ocasik/edit#javascript,live
There is a strange behavior:
If I remove "fnFooterCallback" function my show/hide button works, but when I add it only my third column is hiding and showing.
My questions:
-How to combine fnFooterCallback with show/hide columns
-How to populate my column[9] with data=col[1]/sum(col[1]). Right now I have static value, but for example if in first column in first row I will have 40 and summary of whole first column will be 200 then I would like to have 20% as return value. I think that I need to calculate sum of columns before my table is displayed, but how to do this?
Here is my code:
[code]
var oTable1 = $('#example1').dataTable({
"table-layout": "fixed",
"oLanguage": {
"sZeroRecords": "No data"
},
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iTotal = [0,0,0,0,0,0,0,0];
for ( var i=0 ; i
I am trying to use in specific scenario:
I have 2 tables on my page, both will have data coming from ajax request.
In last column I have button (image) that allows user to move that row from one table to another. Of course when I refresh data with AJAX it will reset, but that's OK :)
Next thing: how to calculate sum and average in footer so that every time I add/remove row it will recalculate?
Something like in this YUI2 example: http://mattparker.github.com/datatable/colstats.html
Enough of what I want, here is what I have :)
My code is available at: http://live.datatables.net/ocasik/edit#javascript,live
There is a strange behavior:
If I remove "fnFooterCallback" function my show/hide button works, but when I add it only my third column is hiding and showing.
My questions:
-How to combine fnFooterCallback with show/hide columns
-How to populate my column[9] with data=col[1]/sum(col[1]). Right now I have static value, but for example if in first column in first row I will have 40 and summary of whole first column will be 200 then I would like to have 20% as return value. I think that I need to calculate sum of columns before my table is displayed, but how to do this?
Here is my code:
[code]
var oTable1 = $('#example1').dataTable({
"table-layout": "fixed",
"oLanguage": {
"sZeroRecords": "No data"
},
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iTotal = [0,0,0,0,0,0,0,0];
for ( var i=0 ; i
This discussion has been closed.