I try to go to a speific page on initComplete:
var table = $('#example').dataTable( {
"initComplete": function( settings, json ) {
table.page(5).draw(false);
}
} );
But it is not working. My page is still at page 1.
I try to go to a speific page on initComplete:
var table = $('#example').dataTable( {
"initComplete": function( settings, json ) {
table.page(5).draw(false);
}
} );
But it is not working. My page is still at page 1.
2
Answers
The problem with your code is that
table
is not defined in your callback contextThe only thing i found in my little research is that you can get the table api from the settings parameter.
https://datatables.net/forums/discussion/34352/passing-datatable-object-to-initcomplete-callback
so maybe it could work like this:
I didnt try though
You have two issues:
.DataTable
not .dataTable
(specifically for the .page() call, not for the initial init)
initComplete
runs,.DataTable({})
has not returned, sotable
is undefinedThis can be confirmed with:
However, in
initComplete
, you can usethis
, so you don’t need thetable
variable.Changing to
.DataTable
andthis
and your code works fine: