每当我刷新网页时:
我首先用一些默认参数初始化我的网格。
function setFilters(grid, gridInfo) {
var model = grid.jqGrid('getGridParam', 'colModel');
postData = gridInfo.postData;
if (postData == null) {
return;
}
grid.jqGrid('setGridParam', { postData: gridInfo.postData });
grid.jqGrid('setGridParam', { search: gridInfo.search });
var filters = {};
if (postData.hasOwnProperty('filters')) {
filters = JSON.parse(postData.filters);
for (var i = 0; i < filters.rules.length; i++) {
var rule = filters.rules[i];
for (var j = 0; j < model.length; j++) {
if (model[j].name == rule.field) {
model[j].searchoptions.defaultValue = rule.data;
}
}
}
}
}
function saveGridParameters(grid) {
var gridInfo = new Object();
gridInfo.url = grid.jqGrid('getGridParam', 'url');
gridInfo.sortname = grid.jqGrid('getGridParam', 'sortname');
gridInfo.sortorder = grid.jqGrid('getGridParam', 'sortorder');
gridInfo.selrow = grid.jqGrid('getGridParam', 'selrow');
gridInfo.page = grid.jqGrid('getGridParam', 'page');
gridInfo.rowNum = grid.jqGrid('getGridParam', 'rowNum');
gridInfo.postData = grid.jqGrid('getGridParam', 'postData');
gridInfo.search = grid.jqGrid('getGridParam', 'search');
return JSON.stringify(gridInfo);
}
function getInitialParams(gridParams, defaultParams) {
var gridInfo = {};
if (gridParams != null && gridParams != "") {
gridInfo = $.parseJSON(gridParams);
gridInfo.rowNum = Number(gridInfo.rowNum);
return gridInfo;
}
else
return defaultParams;
}
var gridParams = $.session.get("main-grid");
var gridInfo = getInitialParams(gridParams,
{
sortname: "StartupPlanYear",
sortorder: "asc",
page: 1,
rowNum: 10
});
var eventList_init = false;
$('#list').jqGrid({
rowNum: gridInfo.rowNum,
rowList: [10, 20, 50],
page: gridInfo.page,
sortname: gridInfo.sortname,
sortorder: gridInfo.sortorder,
beforeRequest: function (a) {
var grid = $('#list');
if (!eventList_init) {
setFilters(grid, gridInfo);
eventList_init = true;
}
},
loadComplete: function () {
if (eventList_init) {
var params = saveGridParameters($("#list"));
$.session.set("main-grid", params);
}
}
});
对于记录,网格很好地完成了工作 - 记录正确显示 但是,其他UI元素,如排序箭头,页码,过滤文本框和页面上的项目 它们最初被分配时显示出来。
如何让网格正确显示从会话中恢复的参数值?