简体   繁体   English

JqG​​rid检查是否选择了该行

[英]JqGrid check to see if the row is selected

Hi im trying to check to see if a row is selected in jqGrid and if it is then toggle the selection. 您好,我试图检查是否在jqGrid中选择了行,然后将其切换。

I know i can deselect the current row using 我知道我可以使用取消选择当前行

`.jqGrid('setSelection', rowid, false);`

and

.jqGrid('resetSelection'); 

applys this to every row in the grid. 将其应用于网格中的每一行。 But i need to check if the row is already selected before i deselect it. 但是我需要在取消选择该行之前检查是否已选择该行。

But what i need to do is an if statement that checks if the selected row is selected and if so do some code but i don't know how to get the true or false value from the row. 但是我需要做的是一个if语句,该语句检查是否选中了选定的行,如果这样做,则执行一些代码,但是我不知道如何从该行中获取真值或假值。 I've tried using and alert to see what the setSelection reruns but it just displays [object object]. 我尝试使用和警报来查看setSelection重新运行的内容,但它仅显示[object object]。 Thank you for any help. 感谢您的任何帮助。

You can use .jqGrid("getGridParam", "selrow") and .jqGrid("getGridParam", "selarrrow") (be carefull in the strange name of the option) to get internal options which hold the last selected rowid and the array of rowids of selected rows. 您可以使用.jqGrid("getGridParam", "selrow").jqGrid("getGridParam", "selarrrow") (请谨慎使用该选项的陌生名称)来获取内部选项,该内部选项保存最后选择的rowid和数组选定行的行标识。 So, if you need to check whether the row with the rowId is selected and you use multiselect: true option, then you can use the following code template 因此,如果需要检查是否选择了具有rowId的行,并使用multiselect: true选项,则可以使用以下代码模板

var selRowIds = $("#grid").jqGrid("getGridParam", "selarrrow");
if ($.inArray(rowId, selRowIds) >= 0) {
    // the row having rowId is selected
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM