How to "select" page on preInit
How to "select" page on preInit
markzzz
Posts: 49Questions: 8Answers: 1
Here's the code I have:
$(document).on('preInit.dt', function (e, settings) {
// retrieve values from url's hash
var apiSettings = new $.fn.dataTable.Api(settings);
apiSettings.search(keysearch);
apiSettings.page.len(length);
apiSettings.page(page);
});
Which correctly set search string and page length to be passed to the server (and displayed on the table on draw), but I'm not able to set which "page". i.e. apiSettings.page(page); has no effect. start is always 0 (and not 10 if page is 3 and length is 5).
What's wrong?
Replies
Use the
displayStart
option. Equally for page length usepageLength
and for the searchsearch
.Allan
At that point data tables doesn't know what the paging is going to look like. I guess you would need to do that on "init", not on "preInit".
This worked (actually it skipped the first 3 pages and landed on page 4. So the first page is obviously page 0).
Just saw @allan 's comment. Probably the better solution :-)
I need preInit because I want to set those values before ajax start and call server for filtering.
@allan where do I find that displayStart? apiSettings.displayStart seems undefined...
Its an option you use in your Datatables init code. See the example in the
displayStart
docs. You should use the documented options rather than directly access the undocumented API as it could change but the documented options will still work.Kevin
@kthorngren I can't, since I'm making general handlers for different grid, not directly within each grid configuration.
i.e. I have 20 grids which must have the same behaviour, without write 20 times the same things.
Can you set defaults as shown here?
Kevin
Ok I see your point. I'll try and let you know in case of problem, thanks guys!
It seems to work.
Thanks