如何在jquery DataTable中停留在活动页面上 [英] How to stay on the active page in jquery DataTable

查看:39
本文介绍了如何在jquery DataTable中停留在活动页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jquery 数据表上列出了几个数据,并且默认数据表插件对其进行了分页.我想在处理数据时获取 dataTable 的当前页面,并在处理操作并重新加载数据后将该页面设置为活动页面.

I have several data listed on the jquery dataTable and its done pagination by the DataTable plugins default. I want to get the current page of the dataTable while processing the data and set that page into active after the action is processed and reload the data.

推荐答案

请参阅此小提琴.您可以看到如何获取当前页面.在 JSFiddle 中,您可以尝试刷新浏览器.例如,假设当前页面现在是 3.当您刷新浏览器时,您仍然在第 3 页.

See this fiddle. You can see how to get the current pages. In the JSFiddle you can try refresh browser. Example let say the current page now is 3. When you refresh the browser, you still in page 3.

为了解决你在编辑或删除行时想回到最后一页的问题,你必须使用这个选项让jquery数据表记住最后一页的位置.Jquery Datatable 将保存表的状态(它的分页位置、排序状态等).状态保存方法使用 HTML5 localStorage 和 sessionStorage API 来高效存储数据.请参阅此链接以阅读有关它的更多详细信息.状态保存

To solve your problem want to go back to the last page when editing or deleting row, u must use this option to make jquery datatable remember where the last page. Jquery Datatable will save the state of a table (its paging position, ordering state etc). The state saving method uses the HTML5 localStorage and sessionStorage APIs for efficient storage of the data. See this link to read more detail about it. State saving

"bStateSave": true

JSFiddle 链接

小提琴演示

Javascript 代码

$(document).ready(function() {
    var table = $('#example').DataTable({
        "sPaginationType": "full_numbers",
        "bStateSave": true
    });

    $("#example").on('page.dt', function () {
    var info = table.page.info();
        $('#pageInfo').html('Currently showing page ' + (info.page + 1) + ' of ' + info.pages + ' pages.');
    });
} );

这篇关于如何在jquery DataTable中停留在活动页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆