我的应用程序用户询问是否可能包含jqGrid的页面记住过滤器,排序顺序和网格的当前页面(因为当他们单击一个网格项目执行任务,然后回到它,他们想它是“当他们离开了”)
Cookie似乎是向前的方式,但是如何获取页面加载这些并在它第一次数据请求之前将它们设置在网格中在这个阶段有点超出我。
有谁有任何经验与这种事情与jqGrid?谢谢!
解决方法
问题解决了
我最终最终在javascript中使用cookie来存储排序列,排序顺序,页码,网格行和网格的过滤细节(使用JSON/Javascript cookies – prefs对象)
保存首选项
– 从$(窗口).unload(function(){…})调用;
var filters = { fromDate: $('#fromDateFilter').val(),toDate: $('#toDateFilter').val(),customer: $('#customerFilter').val() }; prefs.data = { filter: filters,scol: $('#list').jqGrid('getGridParam','sortname'),sord: $('#list').jqGrid('getGridParam','sortorder'),page: $('#list').jqGrid('getGridParam','page'),rows: $('#list').jqGrid('getGridParam','rowNum') }; prefs.save();
加载首选项
– 从$(document).ready(function(){…})调用;
var gridprefs = prefs.load(); $('#fromDateFilter').val(gridprefs.filter.fromDate); $('#toDateFilter').val(gridprefs.filter.toDate); $('#customerFilter').val(gridprefs.filter.customer); $('#list').jqGrid('setGridParam',{ sortname: gridprefs.scol,sortorder: gridprefs.sord,page: gridprefs.page,rowNum: gridprefs.rows }); // filterGrid method loads the jqGrid postdata with search criteria and re-requests its data filterGrid();
jqGrid参考:http://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm
按需求 – 过滤代码
function filterGrid() { var fields = ""; var dateFrom = $('#dateFrom').val(); var dateTo = $('#dateTo').val(); if (dateFrom != "") fields += (fields.length == 0 ? "" : ",") + createField("shipmentDate","ge",dateFrom); if (dateTo != "") fields += (fields.length == 0 ? "" : ","le",dateTo); var filters = '"{\"groupOp\":\"AND\",\"rules\":[' + fields + ']}"'; if (fields.length == 0) { $("#list").jqGrid('setGridParam',{ search: false,postData: { "filters": ""} }).trigger("reloadGrid"); } else { $("#list").jqGrid('setGridParam',{ search: true,postData: { "filters": filters} }).trigger("reloadGrid"); } } function createField(name,op,data) { var field = '{\"field\":\"' + name + '\",\"op\":\"' + op + '\",\"data\":\"' + data + '\"}'; return field; }