我在我的数据表中有分页,并且我实现了选定的行突出显示功能...此功能(行突出显示)在第一页有效,但第二页和第三页无效。
我已经更新了 jsfiddle 中的代码,请查看建议。
var oTable = $("#products").dataTable({
"aaData": [
["one", "two", "three", "four"],
["five", "six", "seven","eight"],
["one", "two", "three", "four"],
["one", "two", "three", "four"],
["one", "two", "three", "four"],
["one", "two", "three", "four"],
["one", "two", "three", "four"]
],
"bProcessing": true,
"bDeferRender": true,
"bFilter": false,
"bJQueryUI": true,
"sPaginationType": "two_button",
"sDom": '<"H"Tfr>t<"F"ip>',
"bRetrieve": true,
"bPaginate": true,
"bSort": true,
"aaSorting": [
[4, "desc"]
],
"iDisplayLength": 5,
"aoColumns": [{
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}, {
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}, {
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}, {
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}, ],
"aoColumnDefs": [{
"fnRender": function (o, val) {
return o.aData[0];
},
"sClass": "prodNbr first",
"aTargets": [0]
}, {
"fnRender": function (o, val) {
return o.aData[1];
},
"sClass": "Description",
"aTargets": [1]
}, {
"fnRender": function (o, val) {
return o.aData[2];
},
"sClass": "Partid",
"aTargets": [2]
}, {
"fnRender": function (o, val) {
return o.aData[3];
},
"sClass": "Description",
"aTargets": [3]
}]
});
$('#products tbody tr').click(function () {
if ($(this).hasClass('selected')) $(this).removeClass('selected');
else
{
$(this).siblings('.selected').removeClass('selected');
$(this).addClass('selected');
}
});