我看到在这段代码中你可以通过
javascript预设postdata过滤器.
postData: { filters:'{"groupOp":"AND","rules":['+ '{"field":"invdate","op":"gt","data":"2007-09-06"},'+ '{"field":"invdate","op":"lt","data":"2007-10-04"},'+ '{"field":"name","op":"bw","data":"test"}]}' }
是否有任何API可以让你建立它.就像是:
jqgrid("#grid").addPostDataFilters("AND"); jqgrid("#grid").addFilteritem("field","cn","value"); jqgrid("#grid").addFilteritem("field1","eq","value2");
我试过这个,但它似乎不起作用:
.jqGrid("setGridParam",{ editurl: "/Project/UpdateMe",ondblClickRow: function (rowid) { editProject(rowid); // window.location.href="/Project/Detail/"+rowid; } }); var grid = $("#grid"); var f = { groupOp: "AND",rules: [] }; f.rules.push({ field: "Name",op: "cn",data: "volat" }); grid.p.search = f.rules.length > 0; $.extend(grid.p.postData,{ filters: JSON.stringify(f) });
更新:
我现在有这个工作(感谢Oleg)但是,如果某个原因,Find按钮有些空白(即使我认为我有一个高级过滤器设置)我添加了一张图片
解决方法
过滤器
filters:'{"groupOp":"AND","rules":[{"field":"invdate",{"field":"invdate",{"field":"name","data":"test"}]}'
您在问题中包含的序列化为对象的JSON版本
var myfilter = { groupOp: "AND",rules: [ { field: "invdate",op: "gt",data: "2007-09-06" },{ field: "invdate",op: "lt",data: "2007-10-04" },{ field: "name",op: "bw",data: "test" } ] }
这可以很容易动态构建:
// addPostDataFilters("AND"); var myfilter = { groupOp: "AND",rules: []}; // addFilteritem("invdate","gt","2007-09-06"); myfilter.rules.push({field:"invdate",op:"gt",data:"2007-09-06"}); // addFilteritem("invdate","lt","2007-10-04"); myfilter.rules.push({field:"invdate",op:"lt",data:"2007-10-04"}); // addFilteritem("name","bw","test"); myfilter.rules.push({field:"name",op:"bw",data:"test"}); // generate to top postdata filter code var grid = $("#list"); grid.jqGrid({ // all prarameters which you need search:true,// if you want to force the searching postData: { filters: JSON.stringify(myfilter)} });
如果网格已存在,则需要使用可以使用的设置重新加载网格
grid[0].p.search = myfilter.rules.length>0; $.extend(grid[0].p.postData,{filters:JSON.stringify(myfilter)}); grid.trigger("reloadGrid",[{page:1}]);