Datatables callback/event when empty ajax response
Datatables callback/event when empty ajax response
The code below does the following things:
1. Sends a request to getData.php to get some data.
2. The spinner is shown when the server-side code is working to retrieve data.
3. The spinner is hidden when the data has come
My problem is that I don't know how to do to hide the spinner even when no data is coming.
The jquery code:
[code]
$(document).ready(function() {
var spinnerOpts = {
// Options for the spinner here...
...
};
var target = document.getElementById('spinn');
var spinner = new Spinner(spinnerOpts);
$('#myTable').dataTable( {
"bProcessing": true,
"sAjaxSource": "getData.php",
"fnPreDrawCallback": function() {
spinner.spin(target); // Show the spinner
},
"fnRowCallback": function() {
spinner.stop(); // Hide the spinner
}
} );
} );
[/code]
The following code sends a json string from getData.php when there is no data:
[code]
echo '{
"sEcho": 1,
"iTotalRecords": "0",
"iTotalDisplayRecords": "0",
"aaData": []
}';
[/code]
1. Sends a request to getData.php to get some data.
2. The spinner is shown when the server-side code is working to retrieve data.
3. The spinner is hidden when the data has come
My problem is that I don't know how to do to hide the spinner even when no data is coming.
The jquery code:
[code]
$(document).ready(function() {
var spinnerOpts = {
// Options for the spinner here...
...
};
var target = document.getElementById('spinn');
var spinner = new Spinner(spinnerOpts);
$('#myTable').dataTable( {
"bProcessing": true,
"sAjaxSource": "getData.php",
"fnPreDrawCallback": function() {
spinner.spin(target); // Show the spinner
},
"fnRowCallback": function() {
spinner.stop(); // Hide the spinner
}
} );
} );
[/code]
The following code sends a json string from getData.php when there is no data:
[code]
echo '{
"sEcho": 1,
"iTotalRecords": "0",
"iTotalDisplayRecords": "0",
"aaData": []
}';
[/code]
This discussion has been closed.
Replies
[code]
fnDrawCallback: function () {
var rows = this.fnGetData();
if ( rows.length === 0 ) {
...
}
}
[/code]
Allan
Why === and not == in the if statement?