<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example1" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th></th>
            <th>A</th>
            <th>B</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th></th>
            <th>A</th>
            <th>B</th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <td>(+)</td>
            <td>A1</td>
            <td>B1</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
( function( window, document, $, undefined ) {
    // On DT Initialization
    $(document).on('init.dt', function(e, dtSettings) {
        if ( e.namespace !== 'dt' )
            return;
        // LiveAjax options
        var options = dtSettings.oInit.pluginTest;
        // True if 'true' or any type of object, and is an ajax table
        if (options === true || $.isPlainObject(options) ) {
            var api = new $.fn.dataTable.Api( dtSettings );
            // If the DT instance was terminated, end the loop
            api.one('destroy.dt', function () {
                alert('Destroy event detected');
            } );
        }
    });
})( window, document, jQuery );
$(document).ready( function () {
  var childTable;
  
  var parentTable = $('#example1').DataTable({
    info: false,
    searching: false,
    lengthChange: false,
    paging: false,
    pluginTest: true,
    columns: [
      {
        width: '50px',
        className:      'details-control',
        orderable:      false,
        defaultContent: '(+)'
      }, {
        title: 'A',
        name:  'A'
      }, {
        data:  'B',
        name:  'B'
      }
    ],
  });
  
  $('#example1 tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = parentTable.row( tr );
        if ( row.child.isShown() ) {
          // Destroy CHILD DT (which does NOT have pluginTest enabled)
          childTable.destroy();
          
          // This row is already open - close it
          row.child.hide();
          tr.removeClass('shown');
        }
        else {
          // Open this row
          row.child( format() ).show();
          tr.addClass('shown');
          
            // Start the sub DT
          childTable = $('#childTable').DataTable({
            lengthChange: false,
            searching: false,
            info: false,
            paging: false
          });
        }
    } );
    function format(){
      return '<table id="childTable" width="100%"><thead><tr><th>Sub DT head</th></tr></thead><tbody><tr><th>Sub DT body</th></tr></tbody></table>';
    }  
} );
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers