How to move between the selected row by Up / Down key ?
How to move between the selected row by Up / Down key ?
Hi Everyone,
I am using the data tables for the first time. It is awesome.
Now, I have a small requirement to navigate between the selected rows with up/down key? How it can be done? Is it available by default in datatables ?
I am using the below function.
Thanks
[code]
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
oTable.fnDeleteRow( anSelected[0] );
} );
/* Init the table */
oTable = $('#example').dataTable( );
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
I am using the data tables for the first time. It is awesome.
Now, I have a small requirement to navigate between the selected rows with up/down key? How it can be done? Is it available by default in datatables ?
I am using the below function.
Thanks
[code]
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
oTable.fnDeleteRow( anSelected[0] );
} );
/* Init the table */
oTable = $('#example').dataTable( );
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
This discussion has been closed.
Replies
No, there isn't a built in method to do this. However it should be relatively simple - you'll need to bind a key event handler, and when you detect the up or down keys, get the currently selected element, then use the fnGetAdjacentTr ( http://datatables.net/plug-ins/api#fnGetAdjacentTr ) plug-in (to know which element is to be selected next). Then simply unselect the current row and select the new one :-)
Allan