row grouping - display other columns

row grouping - display other columns

mmontoyammontoya Posts: 84Questions: 27Answers: 4
edited February 2016 in DataTables

I am using the sample provided for row grouping but I need to show more data from the table in that row.

              "drawCallback": function ( settings ) {
                  var api = this.api();
                  var rows = api.rows( {page:'current'} ).nodes();
                  var last=null;
       
                  api.column(1, {page:'current'} ).data().each( function ( raNum, i ) {
                      if ( last !== raNum ) {
                          $(rows).eq( i ).before(
                              '<tr class="group"><td colspan="4">'+raNum+'</td></tr>'
                          );
       
                          last = raNum;
                      }
                  } );  
                }            

I have some other columns defined:

                {data: "OCNumber", title: "OCNumber"},
                {data: "OldRANumber", title: "Old RA #" },

and would like to add those as well:

                              '<tr class="group">
                                      <td>'+raNum+'</td>
                                      <td>'+OCNumber+'</td>
                                      <td colspan="2">'+OldRANumber+'</td>
                               </tr>'

but not sure how to reference those values in the callback function.

This question has accepted answers - jump to:

Answers

  • mmontoyammontoya Posts: 84Questions: 27Answers: 4
    Answer ✓

    aha!! Not sure if this is the best way but it works :)

                      api.column(1, {page:'current'} ).data().each( function ( raNum, i ) {
                          if ( last !== raNum ) {
                              var data = table.row(i).data();
                              ocNum=data.OCNumber;
                              oldRA=data.OldRANumber;
                              $(rows).eq( i ).before(
                                  '<tr class="group"><td>'+raNum+'</td><td>'+ocNum+'</td><td colspan="4">'+oldRA+'</td></tr>'
                              );
           
                              last = raNum;
                          }
                      } );  
    
  • okkkookkko Posts: 3Questions: 2Answers: 1
    edited July 2016 Answer ✓

    Hello,

    what is table in this line:

    var data = table.row(i).data();

    ?

    edit: nevermind, I accessed the row via rows as per example https://datatables.net/examples/advanced_init/row_grouping.html

    besides, I need grouping by multiple columns, not just displaying another column.

This discussion has been closed.