This is my datatable code:
table = $('#datatable-buttons').DataTable({
lengthChange: false,
pageLength: 25,
order: [ 0, 'desc' ],
//buttons: ['copy', 'excel', 'pdf', 'colvis']
columns: [
{ data: "sample_lab_ref" },
{ data: "sample_client_ref" },
{ data: "sample_client_ref2" },
{ data: "sample_client_ref3" },
{ data: "sample_date" },
{ data: "report_date" },
{ data: "test_parameter_name" },
{ data: "test_parameter_sop" },
{ data: "test_technique_name" },
{ data: "test_value_text" },
{ data: "test_units" }
],
columnDefs: [
{
targets: [4, 5],
visible: false,
searchable: false
}
],
ajax: {
url: "/assets/ajax/test_data_ajax_handler.php",
type: "POST",
data: {
action: "getTestData",
user_data: '<?=json_encode($userData)?>'
}
},
buttons: {
buttons: [
{ extend: 'copy', className: 'btn-info' },
{ extend: 'pdf', className: 'btn-danger' },
{
extend: 'csv',
className: 'btn-success',
text: 'Export to CSV',
exportOptions: {
modifier: {
search: 'applied'
}
}
},
{ extend: 'colvis', className: 'btn-primary' },
]
},
initComplete: function(settings, json) {
table.buttons().container()
.appendTo('#datatable-buttons_wrapper .col-md-6:eq(0)');
}
});
Works fine, but in the event the function in the ajax handler returns NULL (no rows found). How can I tell the datatable to display something like "No data found". Right now it gives me an invalid json syntax error.
No data available in tableif there are zero records in the table, perhaps you need to handle your ajax result to return the table with 0 data rather thanNULL