views:

1597

answers:

2

How does one programically select the top row of a JQGrid. I want to have the top row already selected when it is opened on the page. My grid is sorted by a descriptive column so the first row's id could be any number. I know the method to use I just don't know how to get the rowid for the top (first) row. The method is:

jQuery("#mygrid").setSelection(rowid, true);

I know there must be a simple solution to this but I just can't figure out how to do it.

+1  A: 
$("#mygrid").getDataIds()[0];
Craig Stuntz
try as I might - I could not get this api call to work. Navigating thru the dom however as suggested below worked. Thanks anyway - not sure why the call fails - but it does for me.
MikeD
I think the syntax for jqGrid 3.6 has changed to something like: `$('#mygrid').jqGrid('getDataIDs');`, however this threw an error for me when I tried it using Firebug against the online v3.6 demos.
Sam C
Sam, the old syntax works, as well as the new API. I gave the former since it works on old and new.
Craig Stuntz
my grid setup to get this to work had the following event def: gridComplete: function() { var top_rowid = $('#mygridtbody:first-child tr:first').attr('id'); $("#mygrid").setSelection(top_rowid, true); },
MikeD
+5  A: 

Or, without using the jqGrid API, you should be able to retrieve the top row by navigating the DOM:

var top_rowid = $('#mygrid tbody:first-child tr:first').attr('id');
Sam C
thanks - this worked.
MikeD