jQuery Datatable,保存表的状态,例如分页,搜索等 [英] jQuery Datatable, saving state of the table like pagination, search etc

查看:419
本文介绍了jQuery Datatable,保存表的状态,例如分页,搜索等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用此属性"bStateSave":true以保存jQuery Datatable的状态,但由于某种原因,它对我不起作用.当我刷新页面时,它不会保存搜索结果和分页等信息.是否还有其他参数需要与此参数结合使用.我主要浏览此页面上的信息

So I am using this attribute "bStateSave": true to save the state of jQuery Datatable but for some reason it doesn't work for me. It doesn't save search results and pagination etc when I do the page refresh. Is there some other parameter that needs to go in hand with this one. I am mainly going by the information on this page

http://datatables.net/examples/basic_init/state_save.html

该代码太过庞大而无法发布,我不确定应该过去发布什么.在此先感谢您的帮助.

The code is too freaking huge to be posted and I am not sure what snipped should I used to post. Thanks in advance for your help.

推荐答案

首先,您要确保您具有cookie,并在加载页面后跳入chrome,单击设置",然后显示高级设置" ,"在隐私"部分下,单击内容设置.

First off, you want to make sure you have a cookie, hop into chrome once you loaded your page, click on "settings," then "show advanced settings," under the privacy section click on content settings.

下面是该站点的代码示例,该代码示例在我的Web应用程序中运行正常,并且还确保您具有最新版本的插件.

Below is a code example from that site, that works fine in my web app and also make sure you have the most recent version of the plugin.

$('#MyExampleGrv').dataTable({
    "bStateSave": true,
    "fnStateSave": function (oSettings, oData) {
        localStorage.setItem('DataTables_' + window.location.pathname, JSON.stringify(oData));
    },
    "fnStateLoad": function (oSettings) {
        var data = localStorage.getItem('DataTables_' + window.location.pathname);
        return JSON.parse(data);
    }
});

此代码的作用是创建本地存储而不是Cookie,并且使用特定于页面的方法而不是仅使用称为Datatables的通用标识符,这样,如果您在另一个页面上有一个表,就不会有冲突.如果您使用的是ASP.NET控件和gridview,并且使用ASP.NET中内置的通用CRUD操作(例如EDIT/DELETE/UPDATE)以及您的编辑,则此代码将无法执行的操作,此代码将不会保存分页状态项目位于第3页的分页中,在回发甚至通过AJAX进行部分回发后,它将默认为第1页.

What this code does, is makes a local storage instead of the cookie, and uses a page specific versus just using a generic identifier called Datatables, this way if you have a table on another page, there will be no conflicts. What this code will not do, this code will not save the pagination state if you are using ASP.NET controls and a gridview, if you use the generic CRUD operations built into ASP.NET such as EDIT/DELETE/UPDATE, and your edit item is on pagination page 3, it will default to page 1 after postback and even partial postback via AJAX.

这篇关于jQuery Datatable,保存表的状态,例如分页,搜索等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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