user2046810
user2046810

Reputation: 393

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.

Upvotes: 0

Views: 266

Answers (2)

Tony Tomov
Tony Tomov

Reputation: 3292

If you use Guriddo jqGrid, you can use filterInput method. This method allow to search on all fields in grid data using single input value. Here is description of the method

Here is a demo

Upvotes: 0

Oleg
Oleg

Reputation: 222017

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.

Upvotes: 1

Related Questions