My AJAX call gets JSON data which can sometimes be empty. If I set the paginate option to true, the search and pagination components are shown even if I have 0 results. In which case I set the data to an empty object as [{}]. My settings are as follows:
processing: true,
serverSide: true,
autoWidth: false,
ordering: false,
searching:true,
lengthChange:false,
info: false
The JSON as follows:
draw: 1
length: 10
recordsFiltered: 10
recordsTotal: 1
start: 0
data: [..... list of items]
How to disable these two components if I have no data?
Update: I am not trying to change a setting after render, I am simply not able to understand why is Datatable showing pagination if the results are 0 and is there a way to avoid it. Currently I have hidden it using the xhr event to check the length of the data.
xhrevent and hide the pagination and search DOM elements using jQuery. You can add that as an answer, I will accept it. However I wonder how a library like this doesn't handle this on its own.