$(document).ready(function() { var addSearch = function(elemId) { $('#' + elemId + ' thead td').each( function () { var title = $('#' + elemId + ' thead th').eq( $(this).index() ).text(); $(this).html( '' ); }); } var applySearch = function(obj) { obj.columns().eq( 0 ).each( function ( colIdx ) { $( 'input', obj.column( colIdx ).header() ).on( 'keyup change', function () { obj .column( colIdx ) .search( this.value, true ) .draw(); } ); }); } addSearch('hostlist'); addSearch('joblist'); var jobTable = $('#joblist').DataTable({ 'paging': true, 'info': false, 'dom': 'tp', 'pagingType': 'full', 'ordering': false }); var table = $('#hostlist').DataTable({ 'paging': false, 'info': false, 'dom': 't', 'footerCallback': function ( row, data, start, end, display ) { var api = this.api(), data; // Remove the formatting to get integer data for summation var intVal = function ( i ) { return typeof i === 'string' ? i.replace(/[\$,]/g, '')*1 : typeof i === 'number' ? i : 0; }; // Total over this page hostsTotal = api .rows() .count(); // mem memTotal = api .column( 4, { page: 'current'} ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Update footer $( api.column( 1 ).footer() ).html( $.number(hostsTotal, 0, '.', ' ') ); $( api.column( 4 ).footer() ).html( $.number(memTotal, 0, '.', ' ') ); } }); applySearch(table); applySearch(jobTable); $('td.number').number( true, 0, '.', ' ' ); });