Jonas Stawski
Jonas Stawski

Reputation: 6752

How to set the default column for the search box in jqGrid?

I have specified which columns are searchable through the colModel, but I can't find a way to specify the default column when the search box is opened.

Any help is appreciated.

Upvotes: 2

Views: 1999

Answers (1)

Oleg
Oleg

Reputation: 221997

There are option columns which is not documented in the list of searching options. I wrote recently the answer and the demo which demonstrate how you can implement your requirement.

UPDATED: If you use multipleSearch: true option then you can just follow the referenced answer and specify columns option like I described. The corresponding demo you find here. If you don't like that multipleSearch: true option don't display any searching rule per default you can just add default rule in filters property of postData. For example the next demo is identical to the previous one but it uses additionally

postData: {
    filters: {groupOp: "AND", rules: [{field: "amount", op: "eq", data: ""}]}
}

option.

If you don't want to use multipleSearch: true option then one have to fix small bug in jqGrid to be able to use columns option. One have to modify the lines (see the line 7009 in jquery.jqGrid.src.js) from

} else {
    columns = p.columns;
}

to

} else {
    columns = p.columns;
    cmi = 0;
    colnm = columns[0].index || columns[0].name;
}

I will post the bug report later to trirand and I hope that the bug will be fixed in the next version of jqGrid.

The demo demonstrate working of the suggested fix.

Upvotes: 3

Related Questions