Reputation: 3
I'm using the jQuery datatables plugin with the rowGroup addon.
I need to use the 'startRender' function to display some information in the 'headline' of each group.
Links:
Datatables: https://datatables.net/
RowGroup Addon: https://datatables.net/extensions/rowgroup/examples/initialisation/startAndEndRender.html
But the problem is, that I cant read the row tr Id to get the needed data.
How can I access the row Id inside the startRender function to pass the data in the headline of the group?
Thats my jQuery rowGroup:
rowGroup: {
dataSrc: 1,
startRender: function ( rows, group ) {
var kundenId = table.row( this ).index();
var kundenDomainAnzahl = 1;
var kundenMaxDomainAnzahl = 2;
return group +' ( '+ kundenDomainAnzahl +' / '+ kundenMaxDomainAnzahl +' / '+ kundenId + ')';
}
}
And my table is filled by PHP vars, but in general the rows looks like this:
<tr id="number">
<td>Name</td>
<td>Type</td>
<td>Age</td>
</tr>
Upvotes: 0
Views: 4829
Reputation: 85518
startRender
rows
is actually a dataTables API holding the rows matching the group
. So work directly on rows
, no need for the general table API.
In order to get the <tr>
id's, loop over rows
and grab the id
through nodes()
. Example :
startRender: function ( rows, group ) {
var ids = '';
rows.every(function() {
if (ids.length) ids+=', ';
ids+=this.nodes().to$().attr('id');
})
return 'test id´s : ' + ids;
}
Have jotted down this demo that more or less correspond to the issue you a facing -> http://jsfiddle.net/0x6m94ha/
Update. Using an array and join()
in order to prevent duplicated ids :
startRender: function ( rows, group ) {
var ids = [];
rows.every(function() {
var id = this.nodes().to$().attr('id');
if (!~ids.indexOf(id)) ids.push(id);
})
return 'test id´s : '+ ids.join(', ');
}
demo -> http://jsfiddle.net/0x6m94ha/1/
Upvotes: 1