tags:

views:

35

answers:

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?

+1  A: 

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.

Oleg
Guys, your solutions did helped me resolve my issue. Appreciate your response.
Jack Smith
@Jack Smith: I am glad to hear this, you welcome! Because you are new on the stackoverflow.com I want recommend you to consider to use **voting up** of answers and which was helpful for you and questions which you find interesting. Moreover **additionally** to voting up you can/should **accept** one answer to your question which **solved** your problem (see http://meta.stackoverflow.com/questions/5234/, http://meta.stackoverflow.com/questions/16721/ and other FAQ http://meta.stackoverflow.com/questions/7931/).
Oleg