RowGroup - get the ID of the child rows

RowGroup - get the ID of the child rows

erickherickh Posts: 6Questions: 2Answers: 0
edited June 28 in General

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

  • kthorngrenkthorngren Posts: 13,841Questions: 25Answers: 3,261
    edited June 28

    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 use row().node() to get the HTML. Try something like this:

    var ID = $( rows[0].node() ).find('td').eq(3).data ("id");
    

    You might need to change .eq(3) to .eq(2) for the third column.

    Kevin

  • erickherickh Posts: 6Questions: 2Answers: 0

    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

  • kthorngrenkthorngren Posts: 13,841Questions: 25Answers: 3,261
    Answer ✓

    A little adjustment is needed. rows().nodes() should be used and only the first element of that result used for jQuery find(). Like this:

    var ID = $( rows.nodes()[0] ).find('td').eq(2).data ("id");
    

    Here is the example:
    http://live.datatables.net/leheribi/1/edit

    Kevin

  • erickherickh Posts: 6Questions: 2Answers: 0

    thank you so much my friend !!!!!

Sign In or Register to comment.