用多个“ and”和“ or”条件过滤jqgrid

时间:2018-07-17 13:21:20

标签: jqgrid free-jqgrid

我想使用以下搜索条件过滤jQGrid

Name="Mark" and Age=25 and (city="NY" or city="FL") and (company="xyz" or company="zyx")

下面是我的搜索字符串

{
    "groupOp": "AND",
    "rules": [{
        "field": "Name",
        "op": "eq",
        "data": "Mark"
    }, {
        "field": "Age",
        "op": "eq",
        "data": "25"
    }],
    "groups": [{
        "groupOp": "OR",
        "rules": [{
                "field": "city",
                "op": "eq",
                "data": "NY"
            },
            {
                "field": "city",
                "op": "eq",
                "data": "FL"
            }
        ],
        "groups": [{
            "groupOp": "OR",
            "rules": [{
                    "field": "company",
                    "op": "eq",
                    "data": "xyz"
                },
                {
                    "field": "company",
                    "op": "eq",
                    "data": "zyx"
                }
            ]
        }]
    }]
}

postData: {
    filters: above string
},

,但此搜索无效。请帮助

1 个答案:

答案 0 :(得分:0)

似乎在最后"groups"部分中有一个错误。正确的过滤器应该看起来像

{
    "groupOp": "AND",
    "rules": [
        { "field": "Name", "op": "eq", "data": "Mark" },
        { "field": "Age",  "op": "eq", "data": "25" }
    ],
    "groups": [
        {
            "groupOp": "OR",
            "rules": [
                { "field": "city", "op": "eq", "data": "NY" },
                { "field": "city", "op": "eq", "data": "FL" }
            ],
            "groups": []
        },
        {
            "groupOp": "OR",
            "rules": [
                { "field": "company", "op": "eq", "data": "xyz" },
                { "field": "company", "op": "eq", "data": "zyx" }
            ],
            "groups": []
        }
    ]
}

此外,我强烈建议您包括 jqGrid的版本,您可以使用(可以使用)和fork(free jqGrid,商业Guriddo jqGrid JS或版本<= 4.7的旧jqGrid)。

如果您真的使用“免费jqGrid”(不是版本<= 4.7的旧jqGrid),则可以对本地数据集使用"IN"运算符。该值应为逗号分隔的值列表和

{
    "groupOp": "AND",
    "rules": [
        { "field": "Name",     "op": "eq", "data": "Mark" },
        { "field": "Age",      "op": "eq", "data": "25" },
        { "field": "city",     "op": "eq", "data": "NY,FL" },
        { "field": "company",  "op": "eq", "data": "xyz,zyx" }
    ]
}

另外免费的jqGrid允许将默认的逗号分隔符(可能包含在某些公司名称中)替换为jqGrid选项inFilterSeparator定义的任何替代符号。