html:
<table id="candidates-table" class="display compact nowrap" style="width:100%">
<thead>
<tr>
<th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Drive</th>
<th>Department</th>
<th>Experience</th>
<th>Status</th>
<th></th>
</tr>
</thead>
</table>
js:
var candidateTable = $('#candidates-table').DataTable({
columnDefs: [
{ width: '10%', targets: -1, }
],
"stateSave": true,
"responsive" : true,
"processing": false,
"deferRender": true,
"order": [[3,"disabled"]],
"ajax": {
"url": baseUrl + "admin/candidates",
"dataSrc": ""
},
'fnCreatedRow': function (nRow, aData, iDataIndex) {
$(nRow).attr('id', 'candidate-' + aData.id);
},
"columns": [
{
"render": function (data, type, content, meta) {
return '<input type="checkbox" name="id[]" value="' + content.id + '">';
}
},
{
"render": function (data, type, content, meta) {
return content.firstname;
}
},
]
});
// Handle click on "Select all" control
$('#example-select-all').on('click', function(){
// Get all rows with search applied
var rows = candidateTable.rows({ 'search': 'applied' }).nodes();
// Check/uncheck checkboxes for all rows in the table
$('input[type="checkbox"]', rows).prop('checked', $(this).is(':checked'));
});