68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
$(document).ready(function() {
|
|
$('#hostlist thead td').each( function () {
|
|
var title = $('#hostlist thead th').eq( $(this).index() ).text();
|
|
$(this).html( '<input type="text" class="form-control" placeholder="Search '+title+'" />' );
|
|
} );
|
|
|
|
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( 5, { page: 'current'} )
|
|
.data()
|
|
.reduce( function (a, b) {
|
|
return intVal(a) + intVal(b);
|
|
}, 0 );
|
|
// cpu
|
|
cpuTotal = api
|
|
.column( 6, { 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( 5 ).footer() ).html(
|
|
$.number(memTotal, 0, '.', ' ')
|
|
);
|
|
|
|
$( api.column( 6 ).footer() ).html(
|
|
cpuTotal
|
|
);
|
|
}
|
|
});
|
|
|
|
// Apply the search
|
|
table.columns().eq( 0 ).each( function ( colIdx ) {
|
|
$( 'input', table.column( colIdx ).header() ).on( 'keyup change', function () {
|
|
table
|
|
.column( colIdx )
|
|
.search( this.value, true )
|
|
.draw();
|
|
} );
|
|
} );
|
|
|
|
$('td.number').number( true, 0, '.', ' ' );
|
|
});
|