4

How to operate datatable(jquery plugin) rows with keyboard arrow keys. I did something

var oTable;
    $("#customerdata tbody").click(function(event) {
            $(oTable.fnSettings().aoData).each(function (){
                    $(this.nTr).removeClass('row_selected');
            });
            var row = $(event.target.parentNode);
            row.addClass('row_selected');
            var custid=row.find('td:first').text();
            if(custid!="No data available in table"){
                $('#cust_id').val(custid);
            $('#customerdata_filter input').val('');
            $("#editmodal").dialog("close");}
    });        

    oTable = $("#customerdata").dataTable({
    "bJQueryUI": true,
            "bLengthChange": false,
            "bPaginate": false,
    "sPaginationType": "full_numbers",
            "bProcessing": true,
    "bServerSide": true,
            "sScrollY": "260px",
    "sAjaxSource": "/SrikanthTest/customer.do?type=showMinCustomerDetails"
});

But i don't know how to operate the cursor over the rows.

1

2 Answers 2

3

I think you are looking for something like this, but i need more context to be sure.

$(document).keydown(function (event) {
    switch(event.keyCode)
    {
        var currentRow = $(".row_selected").get(0);
        //arrow down
        case 40:
            $(currentRow).next().addClass("row_selected");
            $(currentRow).removeClass("row_selected");
            break;
        //arrow up
        case 38:
            $(currentRow).prev().addClass("row_selected");
            $(currentRow).removeClass("row_selected");
            break;

    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

I've posted an example that works also with dynamically loaded paged tables in this jQuery dataTables and selecting a row

However, I've used the tab key for usability. I believe it will be easy to change one for another.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.