I define my jquery datatables without HTML except for the base table element. This is my HTML:
<table id="mytable"></table>
Then I do the whole table configuration using the datatables definition. Code example:
var dataSet = [ {name: "storage101", size: 492}, {name: "storage102", size: 742}, {name: "storage103", size: 423} ] $.extend($.fn.dataTable.defaults, { sDom: '<"top"i>rCt<"bottom"flp><"clear">' }); $("#storages").dataTable({ data: dataSet, aoColumns: [ {title: "Name", mData: "name"}, {title: "Size", mData: "size"} ], oLanguage: {sEmptyTable: "No logs"}, fnFooterCallback: function(nRow, aaData, iStart, iEnd, aiDisplay) { var api = this.api(); var size = 0; aaData.forEach(function(x) { size += (x['size']); });
Now I would like to use the footer callback to display the sums of my dataset inside the footer.
Unfortunately, adding HTML to the footer (as in this example: https://datatables.net/examples/advanced_init/footer_callback.html ) does not work, since the table does not contain any tfoot element and the required rows and columns. What would be a clean way to add a footer for all my columns?
JSFiddle with code above: http://jsfiddle.net/36twp251/1/
source share