我正在使用jqgrid版本4.5.2。即使数据已成功过滤,过滤器选项也未正确设置。下面是用于获取过滤器数据的函数。
//retrieve the filter data from the HttpSession in JSOn format successfully.
function loadFilterData(){
var postfiltRet={};
var jsonStr = '';
//Retrieve the filter data from the HttpSession Object in JSON format and passs it to the grid.
jq.ajax({
url: "http://localhost:8080/ui/paw/getstorefltrdata.raws",
processData: false,
contentType: "application/json; charset=utf-8",
type: 'POST',
async:false,
dataType : 'json'
}).done(function(msgRec) {
alert("Retrieved data from first call");
if(msgRec==null && typeof msgRec == "object"){
alert("msgRec retrieved from session is null:" + msgRec);
}
else{
postfiltRet=msgRec;
jsonStr=JSON.stringify(postfiltRet);
alert("Data JSON:" +jsonStr);
}
});
var queueStatus=jQuery('#queueStatus option:selected').val();
finalUrl= "http://localhost:8080/ui/paw/loadworkflowqueuedata.raws?timezone="+&selRole="+ selectedRole+"&"+queueStatus;
jq("#grid").jqGrid({
url:finalUrl,
ajaxGridOptions: {cache: false},//added the option to always reload the grid and not to cache the result.
datatype: 'json',
mtype: 'GET',
colNames:[ 'Requestor Name'],
colModel:[
{name:'requestor',index:'requestor',sortable: true, width:100,editable:false, editrules:{required:true}, editoptions:{size:10}},
{name:'requestorRegion', index:'requestorRegion',sortable: true,width:65,editable:false, editrules:{required:true}, editoptions:{size:8, style: "height: 90%"}, stype:'select', edittype:'select',"searchoptions": {
"value": ":All;Asia Pacific:Asia Pacific;Australia/NZ:Australia/NZ;Europe:Europe;Japan:Japan;Latin America:Latin America;North America:North America"
}}
],
postData: {
},
height: 'auto',
autowidth: true,
rownumbers: true,
pager: '#pager',
viewrecords: true,
sortorder: "asc",
emptyrecords: "Empty records",
loadonce: true,
rowNum:20,
ignoreCase: true,
prmNames: {
nd: null
},
loadComplete: function() {
var $this = jq(this);
var postfilt = $this.jqGrid('getGridParam', 'postData').filters;
alert("postfilt retrieved from the grid: " +JSON.stringify(postfilt));
//store the filter data in the Java object and store the java object in Httpsession.
if(typeof postfilt!='undefined'){
jq.ajax({
url: "http://localhost:8080/ui/paw/storefltrdata.raws",
processData: false,
contentType: "application/json; charset=utf-8",
type: 'POST',
data: postfilt,
dataType : 'json',
async : false
}).done(function(msgRec) {
});
}
else{
alert("postfilt1:" + postfilt);
}
//filter the data using the filters provided.This is working fine data is successfuly filtered but the combobox option of filter not //set correctly.
if ($this.jqGrid("getGridParam", "datatype") === "json") {
setTimeout(function () {
$this.jqGrid("setGridParam", {
datatype: "local",
postData: { filters: postfilt},
search: true
});
$this.trigger("reloadGrid", [{ page: postpage}]);
}, 25);
}
},
jsonReader : {
root: "rows",
repeatitems: false,
page:"page",
total: "total",
records: "records",
cell: "cell",
id: "id"
}
});
jQuery("#grid").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search: false, refresh:true})
.navButtonAdd('#pager',{caption:"Export All",buttonicon:"ui-icon-document",onClickButton: function(){window.open(excelUrl,'_self');},position:"last"});
jQuery("#grid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn",ignoreCase: true });
}
如果我总结上述步骤
1.首先,我以JSON格式获取存储在HttpSession对象中的过滤器。
e.g。 postfilt:{" groupOp":"与""规则" {"字段":" requestorRegion",& #34; OP":"当量""数据":"欧洲"}]}
2.将这些过滤器传递给网格,以便可以在网格中设置它们。
3.根据传递的过滤器过滤网格数据。
我不明白为什么数据被成功过滤但网格上方的过滤器选项设置不正确?我是否错过了过滤器设置或网格定义中的任何内容?请告诉我如果您需要更多信息或遗漏任何内容。