更新。最初的答案是针对 1.9.x。在 dataTables 1.10.x 中要容易得多:
table.on('page.dt', function() {
$('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 'slow');
});
演示 -> http://jsfiddle.net/wq853akd/
另外,如果您使用的是引导版本的数据表,您可能会注意到在使用修复时,页面实际上在滚动到顶部后会向下滚动。这是因为它根据this datatables.net thread 关注单击的按钮。您可以通过在 animate 调用后简单地关注表头来解决此问题,如下所示:
table.on('page.dt', function() {
$('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 'slow');
$('thead tr th:first-child').focus().blur();
});
原答案
您应该定位.dataTables_wrapper 并将事件附加到.paginate_button。这里有一个漂亮的小动画:
function paginateScroll() {
$('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 100);
console.log('pagination button clicked'); //remove after test
$(".paginate_button").unbind('click', paginateScroll);
$(".paginate_button").bind('click', paginateScroll);
}
paginateScroll();
见小提琴 -> http://jsfiddle.net/EjbEJ/