Jqgrid multiselect selected rows count?

2019-05-21 00:50发布

问题:

I'm using Jqgrid by multiselect option. I want to get selected rows count on Jqgrid .

I tried that but no luck...

var count = jQuery('#grid').length;
    if (count > 5)
    alert('The Selected Rows More Than 5')

回答1:

You should just get the length of the array selarrrow:

var selRowIds = jQuery('#grid').jqGrid('getGridParam', 'selarrrow');
alert ('The number of selected rows: ' + selRowIds.length);


回答2:

This works for me: Place a link anywhere you want

<a href="/" id="displayNoSelectedRows">Click me!</a>

and now simply register the callback function

$("#displayNoSelectedRows").click(function() {
    var no = $("input[id^='jqg_gridid_']:checked").length;
    alert(no);
    return false;
});

for this link, where gridid is the table's id. With the knowledge of how the checkboxes are named (or better the way the ids are assigned) this is a possible way to get the number of selected checkboxes.