2
我正在使用jQuery DataTables http://datatables.net/index。是否有可能禁用選定的行上取消選擇?我的意思是在哪裏選擇行並且擁有類row_selected
,然後當我再次單擊它時,它仍然被選中。在數據表中禁用取消選擇
我正在使用jQuery DataTables http://datatables.net/index。是否有可能禁用選定的行上取消選擇?我的意思是在哪裏選擇行並且擁有類row_selected
,然後當我再次單擊它時,它仍然被選中。在數據表中禁用取消選擇
試試這個:
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example 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 delete row */
$('#delete').click(function() {
var anSelected = fnGetSelected(oTable);
oTable.fnDeleteRow(anSelected[0]);
});
/* Init the table */
oTable = $('#example').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;
}
更多信息/演示在這裏:http://datatables.net/examples/api/select_single_row.html