jQuery DataTables Checkboxes: RowGroup
Example for https://www.gyrocode.com/projects/jquery-datatables-checkboxes/
HTML
<link rel="stylesheet" href="https://cdn.datatables.net/v/dt/dt-1.10.16/rg-1.0.2/sl-1.2.4/datatables.min.css">
<script src="https://cdn.datatables.net/v/dt/dt-1.10.16/rg-1.0.2/sl-1.2.4/datatables.min.js"></script>
<link rel="stylesheet" href="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.9/css/dataTables.checkboxes.css">
<script src="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.9/js/dataTables.checkboxes.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<h3><a target="_blank" href="https://www.gyrocode.com/projects/jquery-datatables-checkboxes/">jQuery DataTables Checkboxes:</a> <a target="_blank" href="https://www.gyrocode.com/projects/jquery-datatables-checkboxes/examples/integration/rowgroup/">RowGroup</a></h3>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<hr><a target="_blank" href="https://www.gyrocode.com/projects/jquery-datatables-checkboxes/examples/integration/rowgroup//">See full article on Gyrocode.com</a>
CSS
td.details-control {
background: url('https://cdn.rawgit.com/DataTables/DataTables/6c7ada53ebc228ea9bc28b1b216e793b1825d188/examples/resources/details_open.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('https://cdn.rawgit.com/DataTables/DataTables/6c7ada53ebc228ea9bc28b1b216e793b1825d188/examples/resources/details_close.png') no-repeat center center;
}
JavaScript
function format ( d ) {
return 'The child row can contain any data you wish, including links, images, inner tables etc.';
}
$(document).ready(function (){
var collapsedGroups = {};
var isGroupCollapsedByDefault = true;
var table = $('#example').DataTable({
'ajax': 'https://gyrocode.github.io/files/jquery-datatables/objects.json',
'orderFixed': [3, 'asc'],
'rowGroup': {
'dataSrc': 'office',
'startRender': function(rows, group) {
if (!collapsedGroups.hasOwnProperty(group)) {
collapsedGroups[group] = isGroupCollapsedByDefault;
}
var isCollapsed = !!collapsedGroups[group];
// Assign class name to all child rows
var groupName = 'group-' + group.replace(/[^A-Za-z0-9]/g, '');
var rowNodes = rows.nodes();
rowNodes.to$().addClass(groupName).toggle(!isCollapsed);
// Get selected checkboxes
var checkboxesSelected = $('.dt-checkboxes:checked', rowNodes);
// Parent checkbox is selected when all child checkboxes are selected
var isSelected = (checkboxesSelected.length == rowNodes.length);
// Add category name to the <tr>. NOTE: Hardcoded colspan
return $('<tr/>')
.append(
'<td colspan="4">'
+ '<i class="fas fa-fw ' + (isCollapsed ? 'fa-plus-square' : 'fa-minus-square') + '"></i> '
+ '<input type="checkbox" class="group-checkbox" data-group-name="'
+ groupName + '"' + (isSelected ? ' checked' : '') +'> ' + group + ' (' + rows.count() + ')</td>')
.attr('data-name', group)
.toggleClass('collapsed', isCollapsed);
}
},
'drawCallback': function( settings ) {
},
'columns': [
{
'data': 'id',
'checkboxes':...