jquery.dataTables.TreeTable live example

by royling

HTML

<script src="https://rawgit.com/ludo/jquery-treetable/2.3.1/src/javascripts/jquery.treeTable.js"></script>
<script src="https://rawgit.com/DataTables/DataTables/1.9.4/media/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="https://rawgit.com/DataTables/DataTables/1.9.4/media/css/jquery.dataTables.css">
<script src="https://rawgit.com/royling/jquery.dataTables.TreeTable/master/dataTables.treeTable.js"></script>
<link rel="stylesheet" href="https://rawgit.com/ludo/jquery-treetable/2.3.1/src/stylesheets/jquery.treeTable.css">
<div class="container">
  <table id="example" class="display treeTable initialized-treeTable" width="100%">
    <thead>
      <tr>
        <th>Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Age</th>
        <th>Start date</th>
        <th>Salary</th>
      </tr>
    </thead>

    <tfoot>
      <tr>
        <th>Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Age</th>
        <th>Start date</th>
        <th>Salary</th>
      </tr>
    </tfoot>

    <tbody>
      <tr id="1" class="parent">
        <td>Tiger Nixon</td>
        <td>System Architect</td>
        <td>Edinburgh</td>
        <td>61</td>
        <td>2011/04/25</td>
        <td>$3,120</td>
      </tr>
      <tr id="2" class="child-of-1">
        <td>Garrett Winters</td>
        <td>Director</td>
        <td>Edinburgh</td>
        <td>63</td>
        <td>2011/07/25</td>
        <td>$5,300</td>
      </tr>
      <tr id="3" class="child-of-1">
        <td>Ashton Cox</td>
        <td>Technical Author</td>
        <td>San Francisco</td>
        <td>66</td>
        <td>2009/01/12</td>
        <td>$4,800</td>
      </tr>

    </tbody>
  </table>
</div>

JavaScript

$(document).ready(function() {
  //var table = $('#example').DataTable();

  var table = $('#example').dataTable({
    "sDom": "Ttfrip",
    "oTreeTable": {
      "fnPreInit": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        // This function will be registerd as "aoRowCallback" of jquery.dataTables,
        //  thus it has the same signature as "fnRowCallback".
        // Specify "id" & "class" attributes for each row (TR) required by jquery.treeTable:
        //   for parent rows, add class 'parent';
        //   for children rows, add a class with name of prefix - 'child-of-' and parent id

      },
      "showExpander": true
        // The other settings to override the default options of jquery.treeTable, e.g. childPrefix, etc.
    }
    // The other settings of jquery.dataTables here...
  });


});