如何搜索一行,然后在jqGrid中选择它? [英] How to search for a row and then select it in jqGrid?

查看:84
本文介绍了如何搜索一行,然后在jqGrid中选择它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,必须在jqGrid中以编程方式选择一行.

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

从函数中,我将获得jqGrid中可用的列的值,并且基于传入的列值,我必须在jqGrid中进行搜索,当找到记录匹配项时,我必须选择该行.

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.

不确定如何在我的jqGrid中使用jQuery实现此功能.

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

更新:

您提到的解决方案将搜索第三列(不区分大小写).我想知道是否可以使用正则表达式(即不区分大小写的搜索)在网格的任何列(包括隐藏的列)中进行搜索?

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?

推荐答案

该问题与我

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();

重要的是要考虑到jqGrid有时在colModel中声明的列之前还有其他列.这是"rn"列,其中包含行号.如果使用jqGrid的rownumbers: true选项,则它存在.在使用选项multiselect: true时,还有带有复选框的"cb"列.您可以根据$('#list').jqGrid('hideCol', 'cb');隐藏该列,但是您也应该在那里进行计算.通常,您应该计算所有隐藏的列.

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.

这篇关于如何搜索一行,然后在jqGrid中选择它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆