document.location after pressing pagination button

document.location after pressing pagination button

tardigradtardigrad Posts: 9Questions: 4Answers: 0

When I click a pagination button in my datatable, the page stays at the bottom of the table (I should have said that the pagination buttons are at the bottom).

I made this function to force it back to the top, but it's not working, it only jumps a little bit up, but not to the top.

        function paginateScroll() {
            document.location.href = "#header-row";
            // console.log('pagination button clicked');
            $('.paginate_button').unbind('click', paginateScroll);
            $('.paginate_button').bind('click', paginateScroll);
        }
        paginateScroll();

I'm using chrome.

I see it works perfectly in Firefox.

Answers

  • tardigradtardigrad Posts: 9Questions: 4Answers: 0

    it's a timer problem because this works in chrome:

                setTimeout(function() {
                    document.location.href = "#top";
                }, 10);
    
  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Super - thanks for sharing this with us! I'm sure others will find it useful.

    Allan

  • tardigradtardigrad Posts: 9Questions: 4Answers: 0
    edited May 2016

    I just found a better solution that doesn't write a hash in the url and works in chrome without need to delay

            function paginateScroll() {
                document.getElementById("top").scrollIntoView(true);
                $('.paginate_button').unbind('click', paginateScroll);
                $('.paginate_button').bind('click', paginateScroll);
            }
            paginateScroll();
    
  • tardigradtardigrad Posts: 9Questions: 4Answers: 0

    For the record here is everything I tried

                setTimeout(function() {
    
                    //   doesn't work ------------------
                    $('html,body').animate({
                        scrollTop: $("#top").offset().top
                    }, 'slow');
    
                    //   doesn't work ------------------
                    $('html, body').animate({
                        scrollTop: 0
                    }, 'slow');
    
                    //   doesn't work ------------------
                    var currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
                    if (currentScroll > 0) {
                        window.requestAnimationFrame(smoothscroll);
                        window.scrollTo(0, currentScroll - (currentScroll / 5));
                    }
    
                    //   doesn't work ------------------
                    window.scroll(0,1);
    
                    //   works with 10 delay ------------------
                    document.location.href = "#top";
    
                }, 1000);
    
This discussion has been closed.