Maintain scroll position when using .clear().rows.add(data).draw()

Maintain scroll position when using .clear().rows.add(data).draw()

glimpsed_chaosglimpsed_chaos Posts: 138Questions: 29Answers: 4

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

  • kthorngrenkthorngren Posts: 21,082Questions: 26Answers: 4,908
    edited January 24 Answer ✓

    Thanks for the test case! You can pass either false or page to the draw() API to stay on the same page. See the docs for an explanation of the difference. I used false in this updated example:
    https://live.datatables.net/yitibiqu/1/edit

    Also commented out the chained scrollto call.

    Kevin

  • glimpsed_chaosglimpsed_chaos Posts: 138Questions: 29Answers: 4

    Kevin,

    Well I went down the wrong rabbit hole apparently. That works perfectly.

    Thank you!

Sign In or Register to comment.