jQuery 从 jqGrid 检索选定的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1308873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:10:56  来源:igfitidea点击:

Retrieving selected rows from jqGrid

jqueryjqgrid

提问by Andrew Burns

I have jqGrid 3.5 (full) mostly working. I have it retrieving data with the multi-select option on. The one part I can not get to work is getting the selected rows. The docsstate:

我有 jqGrid 3.5(完整)主要工作。我让它在多选选项上检索数据。我无法开始工作的一部分是获取选定的行。该文档说明:

To obtain selected rows we can use getGridParam('selarrrow') method. Using our example we can write this:

jQuery("#grid_id").getGridParam('selarrrow');

which will return an array with the selected rows (i.e., ["11","9"] from the figure above). The values in array are the id's of the selected rows.

要获取选定的行,我们可以使用 getGridParam('selarrrow') 方法。使用我们的例子,我们可以这样写:

jQuery("#grid_id").getGridParam('selarrrow');

这将返回一个包含选定行的数组(即上图中的 ["11","9"])。数组中的值是所选行的 ID。

This does not work and returns an undefined value (yes I have rows selected). I also have xmlreader:id setup in my grid config.

这不起作用并返回一个未定义的值(是的,我选择了行)。我的网格配置中也有 xmlreader:id 设置。

Can someone point me to a direction to look? I have tried everything I can think of to no avail.

有人可以指点我看的方向吗?我已经尝试了所有我能想到的方法都无济于事。

UPDATE:redsquare was correct about incorrect selectors. my containing div had the same ID as the grid, I noticed this when I went to check my setup code and the selector was table#resultschanged that and it all works. Thanks all. If you post an answer redsquare I will accept it as it is the correct answer.

更新:redsquare 关于不正确的选择器是正确的。我的包含 div 与网格具有相同的 ID,当我去检查我的设置代码时我注意到了这一点,并且选择器已table#results更改,并且一切正常。谢谢大家。如果您发布答案 redsquare,我会接受它,因为它是正确答案。

采纳答案by redsquare

Can you check the selectors for me first. if they are correct can you try to upload your page or replicate the issue at jsbin.com. :)

你能先帮我检查一下选择器吗?如果它们是正确的,您可以尝试上传您的页面或在 jsbin.com 上复制该问题。:)

回答by av1987

Try this, It will return an array of selected rows' id.

试试这个,它会返回一个选定行的 id 数组。

var s;
s = jQuery("#yourGridName").jqGrid('getGridParam','selarrrow');
alert(s);

回答by Mahesh Malpani

var rowKey = jQuery("#yourGridName").jqGrid('getGridParam','selrow');
var rowObject = jQuery('#yourGridName').getRowData(rowKey);

This will also give the row details and using normal . operator you can get column value.

这还将提供行详细信息并使用 normal 。运算符,您可以获得列值。

回答by Leonard

You have to refer not to jQuery object, but to jqGrid itseft.

您不必引用 jQuery 对象,而是引用 jqGrid 本身。

So, during initialization of grid, you write the code like:

因此,在网格初始化期间,您可以编写如下代码:

var myGrid = $("#list")..jqGrid(....);

And in your event handler, if you want to retrieve the IDs of the selected rows, you have to write:

在您的事件处理程序中,如果您想检索所选行的 ID,您必须编写:

var rows = myGrid.getGridParam('selarrrow'); 

回答by cybosser

Another way to get the selected rows: jQuery('#grid').jqGrid('getGridParam','selarrrow');

获取所选行的另一种方法:jQuery('#grid').jqGrid('getGridParam','selarrrow');