Maintain scroll position when using .clear().rows.add(data).draw()
Maintain scroll position when using .clear().rows.add(data).draw()
Link to test case: https://live.datatables.net/pidiruhu/3/
Description of problem: After table is created, new data will periodically be delivered to update the table content. If a user scrolls down into the record set beyond the first viewable rows, say to row 20, after the data update and draw the table is reset to the top (row 1).
I am not using ajax for the data delivery, I'm using a websocket (SignalR).
The expectation is to maintain where a user was scrolled to.
My test case shows attempts using: .scrollTo, .scroller.toPosition, .scroller().pixelsToRow in conjunction with .page.info() and attempts with .scroller.page()
I have pagination set to false and using scroller. A few of the options work if I have pagination set to true.
Any help would be appreciated to get this working.
This question has an accepted answers - jump to answer
Answers
Thanks for the test case! You can pass either
false
orpage
to thedraw()
API to stay on the same page. See the docs for an explanation of the difference. I usedfalse
in this updated example:https://live.datatables.net/yitibiqu/1/edit
Also commented out the chained scrollto call.
Kevin
Kevin,
Well I went down the wrong rabbit hole apparently. That works perfectly.
Thank you!