0

我有一个在 JQuery 中建立的数据表。声明如下:

oTable =
    $('#rules-datatable').dataTable({
    "aoColumns": [
        { "mDataProp": [0], "sWidth": "10%" },
        { "mDataProp": [1], "sWidth": "10%" },
        { "mDataProp": [2], "sWidth": "10%" },
        { "mDataProp": [3], "sWidth": "10%" },
        { "mDataProp": [4], "sWidth": "10%" },
        { "mDataProp": [5], "sWidth": "10%" },
        { "mDataProp": [6], "sWidth": "10%" },
        { "mDataProp": [7], "sWidth": "10%" },
        { "mDataProp": [8], "sWidth": "10%" },
        { "mDataProp": [9], "sWidth": "10%" }
    ],
    "bAutoWidth": true,
    "bFilter": false,
    "bLengthChange": false,
    "bProcessing": true,
    "bServerSide": true,
    "bSort": false,
    "iDisplayLength": 50,
    "sAjaxSource": '@Url.Action("GetAllCapturedRules")',
    "fnDrawCallback": function (oSettings) {
        if (navigator.userAgent.toString().indexOf('MSIE') >= 0) {
            // This fixes the IE8 overflow issue. Style is added after the datatable has been drawn.
            $('#main').addClass('overflow-fix');
        }
    }
});

我试图在单击事件后获取所选行的值,但它似乎不起作用。我的点击事件如下所示:

oTable.click(function () {
    var anSelected = oTable.$('tr.row_selected');
    if (anSelected.length == 0) {
        alert('Please make a selection');
    } else {
        // Get data from the selected row                    
    }
}

在单击事件上,它始终显示“请进行选择”,因此它永远不会获取所选行的值。有人可以解释为什么,以及如何解决这个问题吗?我正在使用数据表 v 1.9.1

4

1 回答 1

0

下面将点击事件添加到每个表格行

oTable.$("tr").on("click", function(){
    //TR that was clicked, you can now get the information from rowClicked
    var rowClicked = $(this);        
});

这是你想要的?

于 2013-04-09T15:17:31.943 回答