camaweb
camaweb

Reputation: 11

jqGrid add custom search operator (ops object)

how can I add search operators without intervening directly in the file jquery.jqGrid.src.js?

example:

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

this change works correctly, but you can do it with an external files?

Upvotes: 1

Views: 1530

Answers (1)

Oleg
Oleg

Reputation: 221997

First of all you should understand that adding custom searching operator is not follow the implementation of the operator. I suppose that you have server side implementation of the searching. In the case extending of searching operation is mostly simple.

The internal structure ops will be changed in the next version of jqGrid. So I recommend you just modify <select> options on the fly inside of afterRedraw. Look at the answer, this one or this one for the corresponding code examples. In your case you can use

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

The demo uses the above afterRedraw and displays

enter image description here

The demo uses local datatype, so the searching with the operation is not work of cause, but postData parameters will be set corresponds to the chosen operation.

Upvotes: 1

Related Questions