数据表 - 回调后保留选定的页码 [英] Datatables - Keeping selected page number after callback

查看:22
本文介绍了数据表 - 回调后保留选定的页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,我应该对其进行一些更改,例如我想更改内容的状态,但该内容位于表格的第 3 页.当我更改它时,数据表会自动刷新到第一页.我想要做的是保留选定的页码并在刷新后调用它.这可能吗?

I have a datatable which I should change something on it, for example I want to change the status of a content, but this content is in 3rd page on the table. When I change it, datatable refreshes itself to the 1st page. What I'm trying to do is to keep the selected page number and call it back after refresh. Is that possible?

顺便说一句,我使用的是数据表 1.9.4

btw, I'm using datatables 1.9.4

解决方案

我所做的只是在我在数据表中所做的每个操作中保留页码并将其发送到控制器,然后通过 TempData 使用它.如果有人需要有关解决方案的帮助,请告诉我,我可以解释得更详细.

What I've done is simply keeping the page number in every action that I make in datatable and sending it to the Controller and then using it via TempData. If anyone needs a hand about the solution, just make me know, I can explain more detailed.

推荐答案

我将数据表状态保存在本地存储中,以避免在我的应用程序中传递页码.我是这样做的:

I save the datatable state in the local storage to avoid passing the page number all over my app. This is how I do it:

$('#offersTable').dataTable({
        "bStateSave": true,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem('offersDataTables', JSON.stringify(oData));
        },
        "fnStateLoad": function (oSettings) {
            return JSON.parse(localStorage.getItem('offersDataTables'));
        }
    });

当您转到另一个页面并且想要返回(使用后退按钮)到上次选择的页面时,这非常有用.

This is very useful when you go to another page and you want to go back (using the back button) to the last selected page.

另见文档:https://datatables.net/blog/2012-01-16

这篇关于数据表 - 回调后保留选定的页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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