So i have datatables lets said name table is reportpr
, and then i have jquery on these table (reload with ajax & json)
here my code :
var table = $('#reportpr');
var target = table.attr('data-table');
var tblDetail = table.attr('data-detail');
var oTable = table.on( 'processing.dt', function ( e, settings, processing ){
if (processing) {
$(this).find('tbody').addClass('load1 csspinner');
} else{
$(this).find('tbody').removeClass('load1 csspinner');
};
}).DataTable({
"bServerSide": true,
"dom": 'Bfrtip',
"buttons": [
'excelHtml5'
],
"scrollX": true,
"scrollY": "200px",
"scrollCollapse": true,
"iDisplayLength": 10,
"ajax": {
"url" : url+"datatable",
"type": "POST",
"data" :{
title: target
},
}
});
Well is work it showing my data, but my problem is how do i check these table if has data or empty (no data).
I try so many thing on these option like $("reportpr").DataTable().rows().count();
OR $("reportpr").DataTable().page.info();
but still not working, anyone any suggesting??? I just need check if my table has data or not.
EDIT :
I edit my question I wanna make another even trigger, so not showing masaage on datatbles, like
if(datatable is empty)
{
button it will enable
}
else
{
button is will disabled
}
Update : I try update my version DataTables from version 1.10.5 into 1.10.16, and try using $("reportpr").DataTable().data().any();
or $("reportpr").DataTable().rows().count();
, is still not working, when that table has data is said i dont have data or empty data. Pls still help these thing.
Probably the simplest way is to count the rows - it will be 0 if empty:
table.rows().count()