1

I have a scenario where in I have to select a row in jqGrid programatically.

From a function I will have a value of a column which is available in jqGrid and based on passed in column's value I have to search in jqGrid and when it finds a record match I have to select that row.

Not sure how to achieve this using jQuery for my jqGrid.

Update:

The solution you mentioned searches for 3rd column (case insensitive). I was wondering is there any way to search in any column in grid (including hidden colums as well) using regext i.e. case insensitive search?

Jack Smith
  • 61
  • 2
  • 7

1 Answers1

5

The question is close to the other question which I answered recently. The distinguish is that you want to search for a selected column. For case-sensitive searching you can use following code

var index = 3;
var str = 'b';
$("#list > tbody > tr > td:nth-child("+index+"):contains('" + str + "')").parent();

For case-insensitive searching the code could look like

var index = 3;
var str = 'b';
var cells = $("#list > tbody > tr > td:nth-child(3)").filter(function() {
                return re.test( $(this).text());
            });
var rows = cells.parent();

It is important to take in consideration that jqGrid has sometimes additional columns before the columns declared in the colModel. This is 'rn' column contains row numbers. It exists if you use rownumbers: true option of jqGrid. In you use the option multiselect: true there are also 'cb' column with check-boxes. You can hide the column with respect of $('#list').jqGrid('hideCol', 'cb');, but you should calculate there also. In general you should calculate all hidden columns.

You can see all live in the following small demo.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798