requestChild
DataTables wants to display a child row.
Description
When stateSave
is active, the requestChild
is triggered when DataTables wants to insert a child row into the table. In this case, a listener has to be set that will implement the insertion of the child row. DataTables cannot handle this as it does not know how to present the data to the user. If no implementation is provided then child rows will not integrate with stateSave
.
The function is passed the row that is being requested to show the child row. In order to identify the correct row, row ids must be set for the table.
Please note that, as with all DataTables emitted events, the event object has a DataTables API instance available on it (the first parameter). Additionally, the events are triggered with the dt
namespace. As such, to listen for this event, you must also use the dt
namespace by simply appending .dt
to your event name, as shown in the example below. The listener must also be set before the table initialisation, otherwise when a state is attempting to load, the functionality to do so will not be available.
Type
function function( e, row )
- Parameters:
Name Type Optional 1 e
No jQuery event object
2 row
No The parent row instance that the child row is attempting to display.
Example
Notification of child row display request:
let table = new DataTable('#myTable', {
ajax: '../ajax/data/objects.txt',
rowId: 'id',
stateSave: true,
columns: [
{
className: 'dt-control',
orderable: false,
data: null,
defaultContent: ''
},
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'salary' }
],
order: [[1, 'asc']]
});
table.on('requestChild', function (e, row) {
row.child(format(row.data())).show();
});