Footer Content calculated in fnFooterCallback not exported

Footer Content calculated in fnFooterCallback not exported

lisah_weducomlisah_weducom Posts: 0Questions: 0Answers: 0
edited December 2012 in TableTools
I have a DataTable, with TableTools, where I am generating column totals in the footer using the fnFooterCallback function. While the footer content display as expected in the HTML version of the DataTables, the export to PDF (or CSV) does not include the footer data as generated in the callback.

DataTables debug bookmarklet: atamaz
DataTables 1.9.4
TableTools 2.1.4

A very basic example, with the minimal amount of code to reproduce the issue: Demonstration: http://dev-3.staging.wedu.com/ttools_test.php

my initialization and fnFooterCallback:
[code]
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay )
{
$(nFoot).append('Grand Totals:');

var tot = 0;
for (var i=0; i

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I'm afraid that TableTools will not pick up data which has been interest into dynamically generated cells like you have. TableTools uses the DataTables stored tfoot cells as you'll be able to see on this line: https://github.com/DataTables/TableTools/blob/master/media/js/TableTools.js#L1613 .

    So the two options are:

    1. Modify TableTools to pull in the data dynamically from the created cells
    2. Modify your initialisation to put the cells in initially and then update their contents rather than recreating them on each draw.

    Allan
  • marwamarwa Posts: 1Questions: 0Answers: 0
    I think the problem that the footer doesn't had the same structure as the datatable
    i mean that tr in the body contains 2 td but tr at the footer contains one td

    I had tried to add Total of debit column at my datatable and export to csv worked

    this is the structure of my datatable




    Type
    Name
    الاسم
    Qty
    Unit
    Price
    Date
    Debit
    Credit




    Loading data from server



    <%--

    Total Debit

    --%>








    Total Debit

    00.00




    and the function that calculates the total debit is

    "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) {
    var total_debit = 0;
    for (var i = 0; i < aaData.length; i++) {
    total_debit += parseFloat(aaData[i]['Debit']);
    }
    var nCells = nRow.getElementsByTagName('th');
    nCells[8].innerHTML = total_debit ;
    }

    the commented part at the section didn't work at the export but when i put the same structure as body it worked

    I hope this will work with you
This discussion has been closed.