DataTables Checkbox Select issue
HTML
<!-- DataTables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css"/>
<link rel="stylesheet" href="https://gyrocode.github.io/jquery-datatables-checkboxes/1.2.12/css/dataTables.checkboxes.css" />
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-4">
<button class="btn btn-danger form-control" id="btnRemoveSelected" style="overflow:hidden">Remove Selected</button>
</div>
<div class="col-md-12">
<table class="display row-border" id="tblShortlistedPlayers" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th width="5%"></th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>205</td>
<td></td>
<td>Aaron Hughes</td>
<td>24</td>
</tr>
<tr>
<td>206</td>
<td></td>
<td>Tony Wells</td>
<td>29</td>
</tr>
<tr>
<td>207</td>
<td></td>
<td>Conor Stark</td>
<td>25</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- PAGE SCRIPTS -->
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<!-- DataTables -->
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
<script...
JavaScript
$(document).ready(function () {
$('#tblShortlistedPlayers').DataTable({
dom: 'Bfrtip',
order: [[2, "asc"]],
lengthChange: true,
searching: false,
ordering: true,
//info: false,
autoWidth: true,
responsive: true,
columnDefs: [
{ visible: false, targets: 0, searchable: false },
{
checkboxes:
{
selectRow: true
},
orderable: false,
targets: 1
}
],
select:
{
style: "multi"
}
});
$('#btnRemoveSelected').click(function () {
let table = $('#tblShortlistedPlayers').DataTable();
ids = [];
// get selected datatables rows
table.rows({ selected: true }).data().each(function (val) {
ids.push(parseInt(val[0]));
});
alert(ids);
});
});