2

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')
Reporter
  • 3,897
  • 5
  • 33
  • 47
dr.linux
  • 752
  • 5
  • 15
  • 37
  • duplicates : http://stackoverflow.com/questions/2587817/how-to-get-row-count-for-jqgrid http://stackoverflow.com/questions/1566617/how-to-count-the-number-of-rows-in-a-jqgrid – xkeshav Aug 26 '11 at 09:06
  • This question is not a duplicate of those posted by diEcho. This question is specific to having the multiselect option turned on (multiselect: true). – Randy Nov 16 '12 at 18:10

2 Answers2

8

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);
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg, wont this would also count empty field as well when multiselect is set to true `` making total of `selRowIds + 1` – Slimshadddyyy Sep 04 '15 at 06:49
  • @Slimshadddyyy: some time before you posted questions about problems with multiselect count, but if I remind me correctly, the problem existed only in combination with some old version of jQuery. I had no demo where I could reproduce the problem. See http://jsfiddle.net/OlegKi/aagxejj5/62/ or http://jsfiddle.net/aagxejj5/61/ in comments to [the question](http://stackoverflow.com/q/31761607/315935). The demos displays **correct** value in all my tests. Which problem exactly you have now? – Oleg Sep 04 '15 at 07:27
  • @Oleg the comment was out of curiosity, possibly my issue could be with older versions. Thanks again for your prompt response..:) – Slimshadddyyy Sep 04 '15 at 08:24
0

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.

Kai
  • 207
  • 4
  • 10
  • Ok, then I misunderstood you. I thought you wanted to count the number of selected rows when using the multiselect option. – Kai Aug 26 '11 at 10:50