English 中文(简体)
How to programmatically select top row of JQGrid?
原标题:

How does one programmatically 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);
最佳回答

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 );
问题回答

The answer above was close, but the case was off. It should be:

$("#mygrid").getDataIDs()[0];

That should work properly.

jqGrid supports a setSelection method it just needs to be called correctly:

var grid = jQuery("#mygrid"),
    ids = grid.jqGrid("getDataIDs");
if(ids && ids.length > 0)
    grid.jqGrid("setSelection", ids[0]);
 $("#mygrid").getDataIDs()[0]; // SO now requires 30 characters, so....

Complete code when table have header row:

var top_rowid = $( #mygrid tr:nth-child(2) ).attr( id ); 
$("#mygrid").setSelection(top_rowid, true);

I ve used the following:

var grid = $( #list );
grid.jqGrid({
    ...
    gridComplete: function() {
        var ids = grid.jqGrid("getDataIDs");
        if(ids.length > 0) { 
            grid.jqGrid("setSelection", ids[0]);
        }
    },
    ...
});

When you have a header row, try this:

var top_rowid = $( #mygrid tbody:first-child tr:nth-child(2) ).attr( id );

If you have header row try this :

$( #tb_par tbody:first-child tr:nth-child(2) ).trigger("click");

If not than :

$( #mygrid tbody:first-child tr:first ).trigger("click");

It will directly trigger click event of the JqGrid.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签