Detecting arrow up/down keypress in the Filter control

Detecting arrow up/down keypress in the Filter control

DatagaardDatagaard Posts: 68Questions: 20Answers: 3

I would like to capture when the up or down arrow button has been pressed while in the Filter control in data tables.

From what I can find by code, is that these keys have been disabled from the dataTables_filter input).on('keypress', function(event).

oTable.on('draw.dt',function () {
    // Deselect any selected row first
    oTable.rows({selected: true}).deselect();
    $('div.dataTables_filter input').on('keypress',function (event) {
        if (event.keyCode === 13 && filteredRows == 1) {
            oTable.row(':eq(0)', { page: 'current' }).select();
            var selectedVND = oTable.rows({selected: true}).data()[0].VENDOR_NO;
            document.location.href="vendorMaint.php?VENDOR_NO=" + selectedVND;
            //alert('Search Enter key pressed');
        }
   });          
});

In doing so would like to make the next / previous row in the data table to be selected.

Is this possible?

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    You could listen for keyup: http://live.datatables.net/hebogiro/1/edit .

    Note that you should not add other event listeners inside the draw event - it would only add it when the draw happens. And then it would add it on every draw (again and again!).

    Allan

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3

    Thanks for the tip on the nested event listener.

This discussion has been closed.