Does Datatables define the child row with a css marker? I have an HTML table that includes child rows. I would like to set these as child rows in Datatables so they stay with the parent row when sorted. I could not find a reference to a css class that marks a row as a child row.
All I could find was the JQuery row.child() function where you add child rows to the row but I am not good with JQuery and can't figure out how to add the row here.
Please see this JSFiddle. (Click "Program" to sort and the list icon to expand/collapse the child rows).
<table id="tprogram" class="table table-striped table-hover ">
<thead>
<tr>
<th class='icon_colunm no-sort'></th>
<th>Program</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-right"> <i class="btn btn-xs fa fa-list-ul" data-toggle="collapse" data-target=".collapsed1"></i>
</td>
<td class='name'>A</td>
</tr>
<tr class="collapse collapsed1">
<td class="text-right"> <i class="fa fa-minus"></i></td>
<td class='name'>a</td></tr>
<tr>
<td class="text-right"> <i class="btn btn-xs fa fa-list-ul" data-toggle="collapse" data-target=".collapsed2"></i>
</td>
<td class='name'>B</td></tr>
<tr class="collapse collapsed2">
<td class="text-right"> <i class="fa fa-minus"></i>
</td>
<td class='name'>a</td></tr>
<tr class="collapse collapsed2">
<td class="text-right"> <i class="fa fa-minus"></i>
</td>
<td class='name'>b</td></tr>
<tr class="collapse collapsed2">
<td class="text-right"> <i class="fa fa-minus"></i>
</td>
<td class='name'>c</td>
</tr>
</tbody>
$(document).ready(function() {
$('#tprogram').dataTable({
"bPaginate": true,
"bSort": true,
"bInfo": false,
"bFilter": true,
"bAutoWidth": false,
"LengthChange": false,
"iDisplayLength": 50,
});
$('#tprogram').on('click', '.fa-list-ul', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
// Open this row
row.child(*?*).show();
tr.addClass('shown');
}
});
});