row().child().remove()
Destroy child row(s) for the selected parent row.
Description
This method is used to remove child row(s) from a parent row, removing them from the displayed table (if they are currently displayed) and releasing the memory allocated for these rows.
Please note that this method is only available when row().child()
is called with a parameter set. This is because row().child()
will return the child rows if called with no parameters, which is either a jQuery
object or undefined
. When called with a parameter row().child()
returns a DataTables.Api
instance. If you need to display a child row without any parameters being set use row().child.show()
.
Unlike many of the other methods which manipulate the DataTable, this method does not require draw()
to be called immediately after. The child row(s) are removed from table without requiring that DataTables redraw.
Type
function row().child().remove()
- Description:
Remove child row(s) from display and release any allocated memory
- Returns:
DataTables API instance.
Example
Show / hide a row based on its current state, adding the row content as needed.:
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'td.details-control', function () {
var tr = $(this).parents('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - remove it
row.child(false).remove();
tr.removeClass('shown');
}
else {
// Open this row (the format() function would return the data to be shown)
row.child(format(row.data())).show();
tr.addClass('shown');
}
});