tags:

views:

691

answers:

1

Is it possible to navigate between rows using the Up and Down arrow keys?

For example, if the first row in the grid is selected and the user presses 'down', I would like the grid to unselect that row and select the next row down in the grid.

There is a post in the jqGrid Forums about this at http://www.trirand.com/blog/?page_id=393/help/navigate-arraw-keys/, but enabling cell edit mode is not a solution for me as it will cause many other undesirable grid behaviors.

+2  A: 
$(document).keypress(function(e) {

if(e.keyCode == 40) { //down arrow
 $('#nextElementId').click();
}
if(e.keyCode == 38 { //up arrow
 $('#previousElementId'.click();
}

});
Daniel Moura
Hmmm... This is a good start, but this code assumes there is only a single grid on the page, and that I can easily get the ID's for each row in the order they are displayed.
Justin Ethier
I used the ID as a simplification. The selected 'tr' has the class ui-state-highlight, using this you can get the next or previous row. You may bind the keypress event to the table instead of 'document', this way you shouldn't have problem with more than one grid.
Daniel Moura