Get paging info in preDrawCallback function
Get paging info in preDrawCallback function

Datatables 1.10.
I initialize my table like this:
dataTable = $('#mytable').DataTable({
//...
"preDrawCallback": function( settings ) {
var table = dataTable;
if (!table) {
table = new $.fn.dataTable.Api( settings );
}
// page is 0 even if I previously set it to different value in hashchange function
var page = table.page() ;
// push state
}
)}
$(window).bind( 'hashchange', function( event ) {
// get page from state via getState
// Code not run when state was change by datatables (eg. in preDrawCallBack)
dataTable.page(page);
alert(dataTable.page()); // shows correct value, eg. page
dataTable.draw():
});
Minor Issue:
dataTable
variable is undefined on first call hence the ìf` block. How should I do this correctly?
Explanation: I use history API (pushState, getState) to enable the back/forward buttons of the browser for pagination navigation and bookmarking of specific pages.
Main issue:
table.page
in preDrawCallback
returns 0 when pressing the back button even if previous page was any other page like page 5.
So state is changed to page 5, pop-up shows 5 correctly, then preDrawCallback
is called and suddenly page value is 0 again.
If I use normal pagination controls of datatables the page values in preDrawCallback
are correct.
What am I doing wrong? What are alternatives?
Answers
dataTable.draw(false):
makes this work.