jquery – jqgrid中是否有api添加高级过滤器来发布数据?

前端之家收集整理的这篇文章主要介绍了jquery – jqgrid中是否有api添加高级过滤器来发布数据?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我看到在这段代码中你可以通过 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");

帮助生成顶部postdata过滤器代码??

我试过这个,但它似乎不起作用:

.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}]);

代替.大多数Web浏览器本身都支持JSON.stringify函数,但可以肯定
你应该在你的页面上包含json2.js.

猜你在找的jQuery相关文章