Retrieving selected rows from jqGrid

2019-02-11 23:38发布

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.

标签: jquery jqgrid
5条回答
萌系小妹纸
2楼-- · 2019-02-12 00:22
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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-12 00:28

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

查看更多
Explosion°爆炸
4楼-- · 2019-02-12 00:34

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'); 
查看更多
ら.Afraid
5楼-- · 2019-02-12 00:37

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

var s;
s = jQuery("#yourGridName").jqGrid('getGridParam','selarrrow');
alert(s);
查看更多
Anthone
6楼-- · 2019-02-12 00:45

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. :)

查看更多
登录 后发表回答