如何使用键盘箭头在jquery数据表中操作行

4
如何使用键盘箭头键操作Datatable(jQuery插件)的行。我已经做了一些工作
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"
});

但我不知道如何在行之间操作光标。

1
有一个同作者的插件可能会对你有兴趣,它叫做 KeyTable。http://www.sprymedia.co.uk/article/KeyTable - Vinko Vrsalovic
2个回答

3
我认为你需要像这样的东西,但我需要更多的上下文才能确定。
$(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;

    }
});

0

我已经发布了一个示例,它也适用于动态加载的分页表格,在这里jQuery dataTables and selecting a row

然而,我为了可用性使用了Tab键。我相信更换一个键也很容易。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接