问题
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 docs state:
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.
This does not work and returns an undefined value (yes I have rows selected). I also have xmlreader:id setup in my grid config.
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#results
changed that and it all works. Thanks all. If you post an answer redsquare I will accept it as it is the correct answer.
回答1:
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. :)
回答2:
Try this, It will return an array of selected rows' id.
var s;
s = jQuery("#yourGridName").jqGrid('getGridParam','selarrrow');
alert(s);
回答3:
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.
回答4:
You have to refer not to jQuery object, but to jqGrid itseft.
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:
var rows = myGrid.getGridParam('selarrrow');
回答5:
Another way to get the selected rows: jQuery('#grid').jqGrid('getGridParam','selarrrow');
来源:https://stackoverflow.com/questions/1308873/retrieving-selected-rows-from-jqgrid