rowGroup.startRender
Provide a function that can be used to control the data shown in the start grouping row.
Please note - this property requires the RowGroup extension for DataTables.
Description
It can be really useful to modify the contents of the grouping row that is displayed by RowGroup. By default it simply shows the grouping data value, but often you might wish to show more complex data, such as aggregations, counts and other summary information. This option provides that ability by letting you specify a function that with return the data to be shown for the group's starting row.
The function defined by this option will be called once for every group shown in the DataTables' current page, and will be called again every time the page is changed (e.g. paging, search or sort) to keep the grouping information current. As such it is important that the function used should be relatively fast in its execution - e.g. do not make any asynchronous Ajax calls!
Types
null
If given as null
the grouping start row is not shown in the table.
startRender( rows, group, level )
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | rows | No | |
A DataTables API instance resulting from | |||
2 | group | No | |
The value of the group's data point (defined by | |||
3 | level | No | |
Since 1.1.0: The nesting level. Top level is index 0. |
Returns:
string
or node
or jQuery
The information returned by the rendering function may be one of:
* A string, in which case RowGroup will create `-tag tr` and `-tag td` elements for the grouping row, with a `colspan` value to have the single cell spanning the width of the table.
* A `-tag tr` node which contains a row that will be injected into the table as the group start row. This is useful if you wish to use multiple cells in the grouping row - e.g. to provide alignment with the host data.
* A jQuery object containing a `-tag tr` node. This acts in exactly the same way as a `-tag tr` element and is provided for convenience.
Default
- Value:
function (rows, data) { return data; }
The default function simply shows the grouping data point's value.
Example
Show the number of rows in the group along with the group data value:
new DataTable('#myTable', {
rowGroup: {
startRender: function (rows, group) {
return group + ' (' + rows.count() + ' rows)';
}
}
});