How to Update the data with ajax and keep the page number
How to Update the data with ajax and keep the page number
Hi,
I have a simple table with a "Last update" column. It shows something like "3 days ago", "5 minutes ago" ... etc.
All data is loaded by one single ajax call, that retrieves the entire table.
I want to see my table up to date without refreshing the page (my clients wants to see the updates and check if something take too time).
So...
I used setInterval function and put ajax.reload() inside.
The datatable reload the data every minute.
It works correctly! ... if you stay on page 1.
But if you browse the table, on page 2, or page 3 ... when setInterval is fired it gets you back to page 1.
It's not a BIG issue ... but, it's not very user friendly, I'd like to ask you guys if you know how to do this correctly.
Features priority:
1. Refresh the data every 60 seconds in order to see the Last Update column changes.
2. Keep the page number if the user is gone away from page 1.
Thanks a lot.
Replies
Assuming you are using
ajax.reload()
then use the second parameter (pass it in asfalse
).If you aren't using that method (there is no way to tell, since there is no link, as required in the forum rules), then we'd need to know how you are reloading the data.
Allan
Hi Allan, I'm sorry, I'm working in localhost and I didn't think to copy and paste my code in a jsfiddle or something like that before posting the question.
But ... I'm using ajax.reload()!!
Now, I've use the second parameter and solve the pagination problem. Thanks for that, now my table keeps the current position.
But I have a new problem: if you are not on page 1, the page scrolls (jump) at the bottom at every call.
Any idea of why?
I've put my piece of code that handle the datatable here:
https://jsfiddle.net/uwjr5r5m/
As in the whole page scrolls to the bottom? I'm afraid I don't know what would cause that. For that one I really would need to be able to spend some time debugging the page showing the issue.
Allan