我正在使用 Datatables 中的示例从表中删除行。这工作正常,一一但我需要选择和删除多行的能力。我评论了//.removeClass('row_selected');
这样用户可以在视觉上选择多行,但这些行一次只能删除一行。想法?
https://datatables.net/release-datatables/examples/api/select_single_row.html
jQuery
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');
}*