Datatables - Keeping selected page number after callback
I save the datatable state in the local storage to avoid passing the page number all over my app. This is how I do it:
$('#offersTable').dataTable({
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('offersDataTables', JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
return JSON.parse(localStorage.getItem('offersDataTables'));
}
});
This is very useful when you go to another page and you want to go back (using the back button) to the last selected page.
See also the documentation: https://datatables.net/blog/2012-01-16
In DataTables 1.10 you have an ability to stay on the same page after re-drawing if you pass false
as a first parameter to the draw()
function.
table.row(index).data(data).draw(false)