Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

jquery - How to search for a row and then select it in jqGrid?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...