在数据表上行选择不起作用

时间:2012-11-11 15:34:31

标签: jquery datatables

我正在尝试允许对我的数据表工作进行行选择(如此处所示:http://datatables.net/release-datatables/examples/api/select_single_row.html)但它似乎不起作用。关于我可能出错的地方的任何想法?

我在这里添加了完整的代码:http://jsfiddle.net/v6VTB/2/

JS

$(document).ready(function () {
    $('#example5').dataTable({
        "bPaginate": true,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": true,
        "bScrollCollapse": true,
        "bInfo": true,
        "bAutoWidth": false
    });
});

var oTable;
var giRedraw = false;

/* Add a click handler to the rows - this could be used as a callback */
$("#example5 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 row */

/* Init the table */
oTable = $('#example5').dataTable();

/* Get the rows which are currently selected */
function fnGetSelected(oTableLocal) {
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();

    for (var i = 0; i < aTrs.length; i++) {
        if ($(aTrs[i]).hasClass('row_selected')) {
            aReturn.push(aTrs[i]);
        }
    }
    return aReturn;
}

1 个答案:

答案 0 :(得分:2)

未定义row_selected类

看到这个小提琴http://jsfiddle.net/v6VTB/3/,在

下添加了一个示例css
.row_selected​{
    color:red;
}​