This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
salt-inventory/www/res/inittable.js

73 lines
2.2 KiB
JavaScript

$(document).ready(function() {
var addSearch = function(elemId) {
$('#' + elemId + ' thead td').each( function () {
var title = $('#' + elemId + ' thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" class="form-control" placeholder="Search '+title+'" />' );
});
}
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, '.', ' ' );
});