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

查看:21
本文介绍了如何在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.

不知道如何使用 jQuery 为我的 jqGrid 实现这一点.

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.

你可以在下面的小demo中看到所有的直播.

You can see all live in the following small demo.

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

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