Search code examples
jqgrid

JQGrid local search multiple columns


I'm using JQGrid with local search (inside the columns header).

I have 2 columns that I want to merge the search for them - so, when I write a value inside the search input this value will be searched in 2 columns at the same time.

Is it possible to implement this? and if so, HOW ??

Thank's In Advance.


Solution

  • If I understand your question correctly you use filterToolbar for searching in a grid which has datatype: "local". In the case jqGrid fills postData.filters parameter in the form described here, which corresponds searching via dialog with multipleSearch: true.

    You can implement your requirements inside of beforeSearch callback of filterToolbar method. Inside of the callback you can use

    var postData = $(this).jqGrid("getGridParam", "postData");
    

    to get the reference on postData object. Then you can use JSON.parse(postData.filters) to convert filter created by filterToolbar to object. It will be object like

    {
        "groupOp": "AND",
        "rules": [{
            "field": "someColumnName",
            "op": "cn",
            "data": "data entered by user"
        }]
    }
    

    You can modify the object by adding one more item in "rules" and setting postData.filters to new value JSON.stringify(modifiedFiltersObject). Finally beforeSearch callback should return false to continue filtering. In the way, you will be able implement your requirements.