我正在尝试允许对我的数据表工作进行行选择(如此处所示: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;
}
答案 0 :(得分:2)