我有一个带有一些记录的jqGrid,并希望根据多个条件过滤记录。
例如,如果有三列,Name,Age和City,我想在以下条件下过滤网格:
Name = "Mark" and Age = 25 and City = 'NY'
以下代码正常 -
var grid = jQuery("#memberDetails");
var postdata = grid.jqGrid('getGridParam', 'postData');
var filterArray = new Array();
var filterConidtion;
filterConidtion = new Object();
filterConidtion.field = "name";
filterConidtion.op = "eq";
filterConidtion.data = "Mark";
filterArray.push(filterConidtion);
filterConidtion = new Object();
filterConidtion.field = "Age";
filterConidtion.op = "eq";
filterConidtion.data = "25";
filterArray.push(filterConidtion);
filterConidtion = new Object();
filterConidtion.field = "City";
filterConidtion.op = "eq";
filterConidtion.data = "NY";
filterArray.push(filterConidtion);
jQuery.extend(postdata, {
filters: {
"groupOp": "and",
"rules": filterArray
}
});
grid.jqGrid('setGridParam', {
search: true,
postData: postdata
});
grid.trigger("reloadGrid", [{
page: 1
}]);
但我不确定如何使以下过滤器工作:
Name = "Mark" and Age = 25 and (City = 'NY' OR City = 'FL')
groupOp
在AND或OR条件下工作,不确定如何在groupOp
感谢。
答案 0 :(得分:5)
the documentation中描述了filters
的格式。要实现更复杂的搜索条件,可以使用groups
的{{1}}属性。相应的代码可以是以下内容:
filters