jquery datatables scroll to top when pages clicked from bottom

后端 未结 7 482
余生分开走
余生分开走 2021-01-02 17:13

I am using a jQuery datatable with bottom pagination. When the pages are clicked from bottom , I want it to scroll it to top, so users do not have to manually do that for lo

相关标签:
7条回答
  • 2021-01-02 18:03

    For those using the bootstrap version of Datatables:

    You may notice that when using the fix from the accepted answer above, the page actually scrolls back down to the paging controls after scrolling to the top. This is because it is focusing on the clicked paging button as per this datatables.net thread. You can fix this by simply focusing on the table header after the animate call like so:

    table.on('page.dt', function() {
        $('html, body').animate({
            scrollTop: $(".dataTables_wrapper").offset().top
        }, 'slow');
    
        $('thead tr th:first-child').focus().blur();
    });
    

    Note: the chained blur()'ing is done so that you the user doesn't see any focused styles on th:first-child.

    0 讨论(0)
提交回复
热议问题