Using fixedcolumns and footerCallback does not sum all of the columns.
Using fixedcolumns and footerCallback does not sum all of the columns.
My table is defined as
if (pTable == 'tblTaskWbsBudgetSumm') {
$('#tblTaskWbsBudgetSumm').DataTable({
"autoWidth":false
, "fixedColumns": {leftColumns: 4 }
, "footer": true
, "info":false
, "language": {"emptyTable":"No Data Found"}
, "JQueryUI":true
, "Order":[0,'asc']
, "ordering":false
, "paging":false
, "scrollY":"600px"
, "scrollX":"1800px"
, "scrollCollapse":true
, "columnDefs": [
{ className: "LeftNoWrap", "targets": [ 0,1] }
]
, "footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data,total;
api.columns('.sum0', {}).every(function() {
var locSum = this
.data()
.reduce(function(a, b) {return fncSumDataTableColumn(a,b);}, 0);
$(this.footer()).html(fncFormatNumber(locSum,0,"Y","Y"));
});
api.columns('.sum2', {}).every(function() {
var locSum = this
.data()
.reduce(function(a, b) {return fncSumDataTableColumn(a,b);}, 0);
$(this.footer()).html(fncFormatNumber(locSum,2,"Y","Y"));
});
}
});
}
Columns 1 & 2 are text.
Columns 3 & 4 are the totals (hours and values) for the remaining n columns in each row. Columns after column 4 all get summed fine.
The problem I am getting is:
If I have "fixedColumns": {leftColumns: 2 }, then columns 3 & 4 get summed into the footer.
If I have "fixedColumns": {leftColumns: 4 }, then columns 3 & 4 don't get summed into the footer.
For some reason, the footerCallback does not get fired on the fixed columns.
I want to fix the total columns, so that when the user scrolls horizontally through the columns, they still see the totals.
Answers
I built this example for another thread and it works with FixedColumns:
http://live.datatables.net/terosali/1/edit
Can you build a test case showing the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I've added http://live.datatables.net/tiduvico/1/edit (I think anyway ).
I've not added the fixedcolumn libraries so it's not scrolling horizontally.
Hope that helps.
Thanks.
I've added the other libraries to the above example and it totals all columns correctly.
However, my data is being added from json.
Hmm, using JSON data shouldn't make a difference. Maybe you can get a few rows example from your array and use it for the data in the example.
Not sure if it would help performance wise but you could build an array of your rows in the for loop then just use the below after your loop to add all the rows at oince:
$('#tblTaskWbsBudgetSumm').DataTable().rows.add(locRow);
Not that it will help the footerCallback
BTW, I added the FixedColumn library to your example:
http://live.datatables.net/tiduvico/3/edit
Kevin
Hi Kevin.
I don't know if this helps, but when I examine the table elements, the footer in the fixed table doesn't have the total values, but the scrolling table does. So the totals are being created, but only in the left hand table, so they aren't visible.