0

I am using jqgrid with multiplegroup option true for search. My filter looks like the following:

{"groupOp":"OR",
"rules":[{"field":"Total_case","op":"eq","data":"29"}],
"groups":[{"groupOp":"AND",
"rules":[{"field":"Total_case","op":"eq","data":"2"},{"field":"percent","op":"eq","data":"100"}],
"groups":[]}]}

I have rows with both total case = 2 ,percent = 100 and total case = 29. Since outer condition is "OR" condition, I am expecting two rows. However it displays no record. What is wrong?

4

1 回答 1

0

这个问题似乎与回答您之前的问题重复。我刚刚在您的原始问题上写了答案,我确认这是当前版本的 jqGrid 中的一个错误。作为一种解决方法,我建议修改具有"groupOp":"OR"两个非空部分的请求rulesgroups以便该rules部分将作为新的附加组插入到groups.

在您发布的示例中,可以首先使用jQuery.parseJSON将您发布的 JSON 字符串转换postData.filters为对象形式

{
    groupOp: "OR",
    rules: [
        {field: "Total_case", op: "eq", data: "29"}
    ],
    groups: [
        {
            groupOp: "AND",
            rules: [
                {field: "Total_case", op: "eq", data: "2"},
                {field: "percent", op: "eq", data: "100"}
            ],
            groups: []
        }
    ]
}

然后可以测试这groupOp是“或”并且两者rules都是groups非空数组。万一可以移动rules里面的部分groups。换句话说,可以将其转换为以下对象

{
    groupOp: "OR",
    rules: [],
    groups: [
        {
            groupOp: "AND",
            rules: [
                {field: "Total_case", op: "eq", data: "2"},
                {field: "percent", op: "eq", data: "100"}
            ],
            groups: []
        }
        {
            groupOp: "AND",
            rules: [
                {field: "Total_case", op: "eq", data: "29"}
            ],
            groups: []
        }
    ]
}

最后,可以使用JSON.stringify将对象转换回 JSON 字符串并将结果分配回postData.filters.

更新:我发布了拉取请求,其中描述了在处理过滤/搜索请求期间将在内部执行 jqGrid 的更改。

该演示使用了该修复程序,现在似乎一切正常。

于 2013-01-25T11:35:10.553 回答