0
我需要選擇在兩個不同的數據表上獨立選擇幾行。這些表具有不同的按鈕,可根據所選行操作表格。以下是爲一個表選擇行的代碼:https://datatables.net/release-datatables/examples/api/select_single_row.html即使我複製了所有代碼並使用了不同的ID,我也無法讓這個表適用於多個表。 http://jsfiddle.net/BWCBX/有什麼想法?爲多個Datatable頁面選擇行?
var oTable;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody tr").click(function(e) {
if ($(this).hasClass('row_selected')) {
$(this).removeClass('row_selected');
}
else {
oTable.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
}
});
/* Add a click handler for the delete row */
$('#delete').click(function() {
var anSelected = fnGetSelected(oTable);
if (anSelected.length !== 0) {
oTable.fnDeleteRow(anSelected[0]);
}
});
/* Init the table */
oTable = $('#example').dataTable();
});
/* Get the rows which are currently selected */
function fnGetSelected(oTableLocal)
{
return oTableLocal.$('tr.row_selected');
}
完美。非常感謝你,控制檯上從未顯示過的簡單監督。 – triplethreat77