RowGroup - get the ID of the child rows
RowGroup - get the ID of the child rows
Hello
I'm using Rowgroup for grouping the rows by the 3rd column (customer) and in my rendering of the group, I would like to retrieve the customer id.
<tr>
<th> Order N ° </th>
<th> Date </th>
<th> Customer </th>
</tr>
<tr>
<td> 300 </td>
<td> 2021-03-21 </td>
<td data-id="500"> Mike </td>
</tr>
<tr>
<td> 301 </td>
<td> 2021-03-21 </td>
<td data-id="500"> Mike </td>
</tr>
<tr>
<td> 302 </td>
<td> 2021-03-21 </td>
<td data-id="500"> Mike </td>
</tr>
<tr>
<td> 400 </td>
<td> 2021-03-25 </td>
<td data-id="501"> Jason </td>
</tr>
Here is my code:
rowGroup: {
startRender: function (rows, group) {
var ID = rows.data().find('td').eq(3).data ("id");
return $ ('<tr />').append ('<td colspan="3">' + group + '' + ID + '</td>)
},
dataSrc: 2
}
But of course that doesn't work.
An idea geniuses?
Thank you
This question has an accepted answers - jump to answer
Answers
rows
is an array of rows for the group. You probably will want to get only the first element in the array. Also you will want to userow().node()
to get the HTML. Try something like this:You might need to change
.eq(3)
to.eq(2)
for the third column.Kevin
Kevin, thank you for your time
when I'm using your solution, that's what Im getting:
rows[0].node is not a function in Chrome console
A little adjustment is needed.
rows().nodes()
should be used and only the first element of that result used for jQuery find(). Like this:Here is the example:
http://live.datatables.net/leheribi/1/edit
Kevin
thank you so much my friend !!!!!