footer row is not getting exported in excel, pdf, csv and html
footer row is not getting exported in excel, pdf, csv and html
i have added footer: true in my buttons and i have fnFooterCallback in my js and footer row is not exported in any of my format
example code
$('#haddy).DataTable({
"buttons": [
{
extend: 'copyHtml5',
text: '<i class="fa fa-files-o"></i>',
titleAttr: 'Copy',
title: ReportTitle,
exportOptions: {
columns: ':visible'
},
footer: true
},
{
extend: 'excelHtml5',
text: '<i class="fa fa-file-excel-o"></i>',
titleAttr: 'Excel',
title: ReportTitle,
footer: true,
exportOptions: {
columns: ':visible'
},
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
var ColInfo = $.grep(dataColumn, function (value, index) {
return value.DisplayName == data.header[j];
});
data.body[i][j] = '\u200C' + data.body[i][j];
}
}
}
}
],
"fnFooterCallback": function (tfoot, data, start, end, display) {
var api = this.api();
var footer = '<tfoot id="rptFooter"><tr class="dataFooter">';
var outvalue = api.column(i).data().reduce(function (a, b) { return a + b; }, 0);
footer = footer + '<th class="' + cclass + '">' + outvalue + '</th>';
footer = footer + '<th></th>';
$(this).append(footer + '</tr></tfoot>');
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
This example is demonstrating that. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
The problem is you are creating the footer after Datatables initializes. It looks for the footer during initialization. Create it before your Datatabales init code. Then use the
footerCallback
to update the footer, like this example.Kevin
we have create a sample test case in the below link
we also tried to added the tfoot tag before binding the data
live.datatables.net/xuwukaqu/1/edit?html,js,output
See this updated example of creating the footer first then using
columns().every()
to loop all the columns in thefooterCallback
to sum them and place the sum in the footer.http://live.datatables.net/ritevixi/1/edit
Kevin