views:

536

answers:

3

How do I count the number of rows in a jqGrid?

To clarify, there is not much data involved so the grid is pulling all of its data back from the server in a single query, instead of using pagination.

A: 

Here is the code I have so far. It seems like there should be a better way:

jQuery("#myGrid").getDataIDs().length;
Justin Ethier
A: 

How about this?

jQuery("#myGrid tr").length;

Actually, you can take that a step further with the optional context parameter.

jQuery("tr", "#myGrid").length;

Either one will search for every "tr" inside of "#myGrid". However, from my own testing, specifying the context parameter is usually faster.

Steve Wortham
+4  A: 

jQuery("#myGrid").getGridParam("records");

JacobM
Ah yes, I should've known more about the jqGrid before answering. Here's a reference: http://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm
Steve Wortham
Just so you know, the latest docs have been moved to a Wiki: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
Justin Ethier
JacobM - Thanks, I knew there had to be a better way! Also, now that I actually read this section of the docs :) - you may want to add a description of reccount which does something similar.
Justin Ethier