bug with server-side pagination
bug with server-side pagination
eaglesh
Posts: 7Questions: 1Answers: 0
Hi, I'm using server-side processing and I can't set page like this:
table.page(pageIndex).ajax.url('someUrl').load(function() {
table.columns.adjust();
window.scrollTo(0, scroll);
}, false);
I try to change source dynamically that can help me quickly jump into some record on the table to display some another data and jump back. When I jump into record I save page index and sroll position, when I jump back I want to restore page index. But if the page wich I jump from contains only one page then _fnPageChange() can't allow me set page > 0.
P.S. Sorry for my English ((
This discussion has been closed.
Answers
Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.
Information on how to create a test page, if you can't provide a link to your own page can be found here.
Thanks,
Allan
Thank you for so fast reply.
I think it's difficult to set-up a remotely hosted test case with server-side proccessing. But how can I load data from server but from needed page (for example from 6th page)? I think it will help me to resolve my problem.
The
start
parameter that DataTables sends to the server tells the server where the data should start the data from (i.e. page = start * length).Beyond that, I really would need a test case i'm afraid.
Allan
I have found out in debug mode that when I call
table.page(pageIndex).ajax.url('someUrl').load(null, false)
start
parameter calculated in _fnPageChange based on state (or settings) of current page. But if current page contains no rows thenstart
will be reseted here in _fnPageChange of jquey.dataTables.js:But I have changed source data by
.ajax.url('someUrl')
and atsomeUrl
there are much data.A page cannot have zero rows. It wouldn't exist if it had zero rows.
Allan
Sorry, I mean no records in the table, for example first source server returned answer with zero records.
Here some test case for debug:
https://output.jsbin.com/yunuzugiwo
All buttons run scripts that should change source and page. But all of them change only source, and all ways (buttons) will send start=0 to the server
P.S. Before retry with any other button you should reload page to reset "draw" count parameter
Don't call the
load()
method - since you are server-side processing it will load the data on the next data anyway.However, there is another issue - your first page loads only 1 row. So trying to set it to page 3 isn't going to work as there is no page 3.
So:
way 1) Doesn't work because there is no
page(3)
to turn toway 2) Doesn't work because again, the is no
page(3)
and that is executed before the new data is loadedway 3) Does work, but it sends a redundant request to the server (one for the
load()
and one for thepage(3)
.Allan
So, how should I switch data source? For example, current data source returned only one record. Then I want to switch to another source with more than thousand records and load from page 3?
I tried to switch source, and then reload with page 3 (way 3). But seems like callback executes earlier than settings (or state) get updated (because the new source has much data and many pages, but still start=0 is send to the server).
Way 3 appears like it should work. It will send a redundant request as I noted, but then it will send another request to get the third page. You could wait for the first page to load before then sending the request for the third page which might be more reliable.
There is no way to tell DataTables to page past what it has been told is the current length of the table (which it appears is what you are struggling to do at the moment).
Allan
This is works for me.
where restorePage is a function like:
I am noob in javascript. I killed much time to find solution. Function setTimeout is very helpful in my case.