How to prevent the page jumping to top when sorting

How to prevent the page jumping to top when sorting

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

As the header says, when I sort, the page goes to the top each and every time, how can I prevent that, so it would sort and stay where it is?

Replies

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    I'm bumping this, as there are no other discussions talking about it with a reply :blush:

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Take a look at this thread here - it's not possible to do...

    Cheers,

    Colin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited May 2018

    My problem is not going to the first page (as I do not have any pagination anyway). My problem is that if I scroll a little bit, and then click on sort, the page itself goes to the top, and doesn't stay a bit scrolled. Do you know what I mean?

    I think the problem comes from the fact when I sort, the processing: true redraws my table, and thus scrolling the page to the top.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look if you can provide a working example demonstrating the problem,

    Cheers,

    Colin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    I found the answer, I'll put it here for reference. You should add this to your datatables to save the current scroll position before redrawing it :

    "preDrawCallback": function (settings) {
        pageScrollPos = $('body').scrollTop();
    },
    "drawCallback": function (settings) {
        $('body').scrollTop(pageScrollPos);
    },
    
This discussion has been closed.