is there an api in jqgrid to add advanced filters to post data?
The filter
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"}]}'
which you included in the question is serialized to JSON version of the object
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" }
]
}
which can be easy constructed dynamically:
// 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)}
});
if the grid already exist you want to reload the grid with the settings you can use
grid[0].p.search = myfilter.rules.length>0;
$.extend(grid[0].p.postData,{filters:JSON.stringify(myfilter)});
grid.trigger("reloadGrid",[{page:1}]);
instead. The function JSON.stringify
is supported by the most web browsers natively, but to be sure
you should include json2.js on your page.