gpt4 book ai didi

jquery - jqgrid中有没有一个API可以添加高级过滤器来发布数据?

转载 作者:行者123 更新时间:2023-12-03 22:29:10 25 4
gpt4 key购买 nike

我在这段代码中看到了如何通过将其放入 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) });

更新:

我现在可以使用此功能(感谢奥列格),但如果由于某种原因“查找”按钮出现空白(即使我确实有高级过滤器集),我也添加了一张图片

enter image description here

最佳答案

过滤器

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"}]}'

您在问题中包含的内容已序列化为对象的 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}]);

相反。大多数网络浏览器本身都支持 JSON.stringify 函数,但可以肯定的是你应该包括 json2.js在您的页面上。

关于jquery - jqgrid中有没有一个API可以添加高级过滤器来发布数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5272850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com