3

Maybe this information is out there and my Google-fu is failing me, however I can't seem to find the answer. How can I get the number of rows being currently displayed in a jqGrid?

Every question and answer I've found on this topic tells you how to get either the total number of rows (displayed or not) or the number of rows loaded by an external service. Instead, I'm trying to get how many rows are being displayed in the current page of the jqGrid. One of my jqGrid attributes is rowList:[10,20,30], but I'm not sure how to access which one is selected myself.

All I want is how many rows are being currently dislpayed on each page of the jqGrid. The closest thing I've found so far has been this Q&A, but this displayed how many <tr>s there are and wasn't really what I needed.

Community
  • 1
  • 1
asteri
  • 11,402
  • 13
  • 60
  • 84

3 Answers3

2
$('.ui-pg-selbox').val()

Tested on the latest jqGrid (4.4.1)

Of course, if you have more than jqGrid per page, you can use an wrapper to ensure that it is the one you're looking for.

$('#myjqGridWrapper .ui-pg-selbox').val()

Not sure whether it's the best way, but it gets the job done.

The space means a descendant selector, that is it looks for elements containing the class ui-pg-selbox which are descendant of an wrapper #myjqGridWrapper. That would require having a div or some other wrapper around your table.


UPDATE: Also, if you have the table ID or a reference, you can use a more sturdy way of querying its jqGrid instance's .ui-pg-selbox:

$('#jqgridTableId').closest('.ui-jqgrid').find('.ui-pg-selbox').val()
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
  • I'm afraid that doesn't work for me. In `var rowCount = $('#searchTable.ui-pg-selbox').val();`, the variable `rowCount` remains undefined after execution. – asteri Nov 19 '12 at 20:49
  • You forgot the space after `#searchTable` -> `$('#searchTable .ui-pg-selbox').val();` – Fabrício Matté Nov 19 '12 at 20:50
  • Wow. Can you explain why that works with the space and not without it and put that in your answer? The id of my table doesn't include a space. I thought elements of an object were always accessed directly with the dot after them? – asteri Nov 19 '12 at 20:52
  • Is `searchTable` the ID of the table or an wrapper? Just to make sure before I write it in the answer. – Fabrício Matté Nov 19 '12 at 20:54
  • It's the ID. And actually adding the space didn't work, haha. But the first version without the identifier works fine for my purposes, since I don't have multiple jqGrids anyway. – asteri Nov 19 '12 at 20:55
  • @Jeff I've added a version that uses the table id and explained the other. Even though explaining the other isn't of much help now. `=]` – Fabrício Matté Nov 19 '12 at 20:58
  • Thank you, sir. You've been very helpful! Been searching for something like this for way longer than I should have. Haha – asteri Nov 19 '12 at 20:59
2

The following will return you the number of displayed rows on a grid's page:

$('#myjqGridWrapper').getGridParam('reccount');
vadim
  • 993
  • 13
  • 29
-1

You shouldn't rely on the view for information. You should pull this information out of the JQGrid model. You can do so by calling the getGridParam method like so:

var rowNum = jqGrid.getGridParam('rowNum');

See here for more information: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

Sean Anderson
  • 27,963
  • 30
  • 126
  • 237
  • From the documentation: "rowNum - Sets how many records we want to view in the grid.". In other words, if he has 7 rows in total, but has choosen to see 10 rows per page, then jqGrid.getGridParam('rowNum') will return 10, not 7. – vadim Dec 29 '15 at 16:23