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

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

问题描述

我有一个数据表,我应该对其进行更改,例如,我想更改内容的状态,但是该内容在表的第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

解决方案

我要做的只是将页码保留在我在数据表中执行的每个操作中,然后将其发送到Controller,然后通过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天全站免登陆