jquery - 后退按钮可移动数据表的第n页

标签 jquery grails datatables

假设我们在数据表中有n页,并且该数据表的一列具有通过发送新请求来打开新页面(仪表板)的链接。

我们必须在此新页面(仪表盘)上添加后退按钮,这样才能将我们移至数据表的最后打开的页面。

我们像这样应用后退按钮-

<button style="postion:fixed;" class="pull-right" onclick="window.history.go(-1); ">Back</button>

但是此按钮会将我们发送到数据表的第一页,而不是打开链接的第n页。
enter image description here

最佳答案

您可以将页码保存在第一个URL的哈希中,如下所示:

<a href="secondPage.html" onClick="window.location.hash = encodeURIComponent(JSON.stringify({page: table.current_page_in_table}));">link</a>

然后,在加载页面后,检查您是否具有哈希,如果有,请读取页码并更新表以转到该页面:
<script type="text/javascript">
    function goToRightPage() {
        if (window.location.hash) {
            // Read the hash string omitting the # prefix
            var hashJson = window.location.hash.substring(1);
            // Restore the deserialized data to memory
            myData = JSON.parse(decodeURIComponent(hashJson));
            datatable.goToPage(myData.page);
         }
    }
    window.onload = goToRightPage;
</script>

关于jquery - 后退按钮可移动数据表的第n页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796135/

相关文章:

javascript - 为什么我不能使用 off() 删除事件监听器?

javascript - Select2 下拉更改事件不起作用

jQuery 数据表 : control table width

javascript - Laravel-数据表保护

javascript - Ajax 请求加载时间过长

jquery - 获取 100% 宽的 LI 中 html 内容的宽度

unit-testing - 在 grails 2.3.8 中测试通过后出现 ScriptExitException

ajax - 如何通过ajax对输入元素的模糊调用 Action 方法

grails - 我需要过滤具有内联单元格编辑的yui数据表。并且数据来自groovy Controller ,其键为:值对形式。作为JSON

javascript - 将html表格导入html页面