Check if table in not empty inside footerCallback
Check if table in not empty inside footerCallback
itajackass
Posts: 165Questions: 49Answers: 3
I've now this working footerCallback:
$('#table').DataTable( {
footerCallback: function(row, data, start, end, display) {
var api = this.api();
var footer = $(this).append('<tfoot><tr></tr></tfoot>');
this.api().columns().every(function () {
var column = this;
if ($(column.header()).hasClass('sum')) {
var sum = column
.data()
.reduce(function(a, b) {
var x = parseFloat(a) || 0;
var y = parseFloat(b) || 0;
return x + y;
}, 0);
} else {
var sum = "";
}
$(footer).append('<th class="text-left">'+sum+'</th>');
});
}
});
When the table (built from ajax) is not empty, all is ok. But if it is empty result, the footer break!
How can i check if table is not empty INSIDE the footerCallback? I've tried if ( !this.data().any() ) without success
I'd like to prevent footer creation if table is empty
This discussion has been closed.
Answers
Solved. sorry
You could try
page.info()
to get the number of records.Kevin