jqGrid添加自定义搜索运算符(ops对象)

时间:2013-05-11 10:25:41

标签: jquery search jqgrid

如何在不直接插入文件jquery.jqGrid.src.js

的情况下添加搜索运算符

示例:

ops: [
    {"name": "eq", "description": "equal", "operator": "="},
    {"name": "ne", "description": "not equal", "operator": "<>"},
    {"name": "lt", "description": "less", "operator": "<"},
    {"name": "the", "description": "less or equal", "operator": "<="},
    {"name": "gt", "description": "greater", "operator": ">"},
    {"name": "ge", "description": "greater or equal", "operator": "> ="},
    {"name": "bw", "description": "begins with", "operator": "LIKE"},
    {"name": "bn", "description": "does not begin with", "operator": "NOT LIKE"},
    {"name": "in", "description": "in", "operator": "IN"},
    {"name": "ni", "description": "not in", "operator": "NOT IN"},
    {"name": "ew", "description": "ends with", "operator": "LIKE"},
    {"name": "en", "description": "does not end with", "operator": "NOT LIKE"},
    {"name": "cn", "description": "contains", "operator": "LIKE"},
    {"name": "nc", "description": "Does not contain", "operator": "NOT LIKE"},
    {"name": "noo", "description": "is null", "operator": "IS NULL"},
    {"name": "nn", "description": "is not null", "operator": "IS NOT NULL"},
    {"name": "xx", "description": "xxx", "operator": "CUSTOM"} ]

此更改正常,但您可以使用外部文件吗?

1 个答案:

答案 0 :(得分:1)

首先,您应该了解添加自定义搜索运算符不遵循运算符的实现。我想你有服务器端实现的搜索。在搜索操作的扩展大多简单的情况下。

内部结构ops将在下一版本的jqGrid中更改。因此,我建议您只需在<select>内动态修改afterRedraw选项。请查看the answerthis onethis one以获取相应的代码示例。在您的情况下,您可以使用

afterRedraw: function () {
    $(this).find("table.group td.operators>select.selectopts")
        .append("<option value='xx'>xxx</option>");
}

The demo使用上述afterRedraw并显示

enter image description here

该演示使用 local datatype,因此使用该操作进行搜索不是原因,但postData参数将设置为对应于所选操作。