Am I trying to use saveState the wrong way?
Am I trying to use saveState the wrong way?
I am using an ajax call to load a table that is hooked up to datatables and it's working fine. I also have a refreshing function, that reloads the same script using ajax on a 30 second interval. The first time through the refreshingCount is set to 0 and it runs the datatable with the setup options. On every call after that it skips the initialization portion of the ajax call and what I was hoping would happen is that it would update each row with the new data and if a user had sorted a column prior to the refresh, it keeps that ordering so the user doesn't have to re-sort every 30 seconds. Is this what saveState is supposed to do?
$.ajax({
type: "POST",
url: "something.php",
data: dataString,
cache: false,
success: function(html) {
$(".my-data-table-div").html(html);
init();
if (refreshingCount == 0) {
$('.my-data-table').DataTable({
"paging": false,
stateSave: true,
})
refreshingCount++;
}
}
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
StateSave is used when the page is reloaded. The problem is that Datatables doesn't know about the updated table with the method you are using. This thread discusses some options you can try.
Kevin