pagination is resetting after data reload
pagination is resetting after data reload
waqqad
Posts: 7Questions: 1Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
This question has an accepted answers - jump to answer
Answers
You haven't provided information about your solution or what is causing the problem. I will guess you are using
ajax.reload()
and want to stay on the same page. See the second example in theajax.reload()
docs to see how to do this.If this doesn't help then please provide more details.
Kevin
hello,
i updated datatables from 1.13 to 2.1.8 version, it's working fine except when reloading data using
table.clear().rows.add(data).draw(false);
the pagination is reset to page 1.
any advise?
hello keven,
thanks for your prompt responce.
i am not using ajax, i just get data through api call to google apps script from google sheets
It is, because when you call
clear()
the table rows are reduced to 0, thus paging must be reset.If you know you are going to be adding the same number of rows again, then store the current page start point (
page()
) and then set it again after you've added the new data.Allan
hello allan,
thanks for your answer, however it was working perfectly before upgrade, moreover the data rows might increase after every update
There must have been changes in 2.x to affect the behavior of
clear()
anddraw()
. As Allan suggested usepage()
to get the current page before reloading the table. Then usepage()
, after reloading, to go to the stored page.Kevin
var currentPage= table.page()
console.log(currentPage)
table.clear().rows.add(data).page(currentPage).draw(false);
or table.clear().rows.add(data).page(currentPage).draw('page');//<<<this eleminates the data
i did that as well kevin, but still the same issue
i did it this way and now working.
var currentPage= table.page()
console.log(currentPage)
table.clear().rows.add(data).draw(false);
table.page(currentPage).draw(false);
thanks
I tried it here:
https://live.datatables.net/kapecenu/1/edit
You are correct. You need to call
draw()
for Datatables to update sorting, searching, etc with the new data. Add adraw()
call afterrows.add()
, like this:You can try it in the test case.
Kevin
thanks kevin