Search code examples
jquerydatatablefooter

DataTable Footer create through options?


So I am creating a DataTable on the page with information grabbed from an ajax call.

//Initialize table
var table = $("#table").DataTable({
    deferRender: true,
    sDom: "t" +
        "<'dt-toolbar-footer' i " +
        "<'dataTables_info total'>" +
        ">" + "S",
    language: {
        searchPlaceholder: "Search",
        search: "_INPUT_" //no label
    },
    scrollY: 250,
    scrollX: true,
    scrollCollapse: false,
    autoWidth: true,
    data: wholeData,
    aoColumns: columns,
    order: order,
    footerCallback: footerCallback
}); // END TABLE /////////////////

Cannot for the life of me figure out how to generate a footer within these options: DataTable Options.

How do I create a footer without placing <tfoot> tags inside the HTML?


Solution

  • Unfortunately DataTables does not currently have support for creating the footer inside the options. DataTable Footer create through options

    Although Allan suggests this problem will be looked at in future versions.

    For now I just solved the problem by creating the <tfoot> DOM dynamically.

    var footer = $("<tfoot></tfoot>").appendTo("#table");
    var footertr = $("<tr></tr>").appendTo(footer);
    
    //Add footer cells
    for (var i = 0; i < Columns.length; i++) {
        $("<td>" + Columns.FooterText + "</td>").appendTo(footertr);
    }