I have datatable:
function drawRadnici() {
$('#tableradnici').dataTable({
"ajax": {
"url": 'track_radnici.php',
"type": 'POST',
"data": {ajdi:ajdi},
},
paging: false,
//"dom":' <"search"f><"top"l>rt<"bottom"ip><"clear">',
// end ,
"columns": [ {
"data": "datum"}, {
"data": "radnik"},{
"data": "radnih_sati"},{
"data": "cena"},{
"data": "ukupno"},{
"data": "ID"}
],
"columnDefs": [
{
"targets": 5,
"data": "ID",
"render": function(data, type, full, meta) {
// return data;
return '<i value="'+data+'" class="fa fa-times"></i>';
}
}
]
});
};
and work fine, but when I have empty JSON data from database then I get:
Uncaught TypeError: Cannot read property 'length' of null
MY json when I havent data is:
{data:null}
WHat I was try to do - I try to add success function to ajax:
"ajax": {
"url": 'track_radnici.php',
"type": 'POST',
"data": {ajdi:ajdi},
"success": function (data) {
if (data == null) {
$('#tabeleradnici').html('No result');
}
}
},
so I try when I dont have data to add just text to #tabeleradnici ... but this also dont work ...