简体   繁体   中英

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.

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. I've tried using and alert to see what the setSelection reruns but it just displays [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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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