<!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">
      <button id="get-open">Get Open ID's</button> <span id="ids"></span>
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th></th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Salary</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th></th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Salary</th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <td></td>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>$3,120</td>
          </tr>
          <tr>
            <td></td>
            <td>Garrett Winters</td>
            <td>Director</td>
            <td>Edinburgh</td>
            <td>$5,300</td>
          </tr>
          <tr>
            <td></td>
            <td>Ashton Cox</td>
            <td>Technical Author</td>
            <td>San Francisco</td>
            <td>$4,800</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;
}
 
$.fn.dataTable.Api.register( 'rows().getOpenChildren()', function ( exclude ) {
    return this.iterator( 'rows', function ( settings, row ) {
        return this.rows().indexes()
                .filter( function ( value, index ) {
                    return this.row( index ).child.isShown() && index !== exclude;
                } ).toArray() || undefined;
    }, 1 );
} );
function format (  ) {
    return 'HIIII';
}
 
$(document).ready(function() {
    var table = $('#example').DataTable( {
      
        "columns": [
            {
                "className":      'details-control',
                "orderable":      false,
                "defaultContent": ''
            },
            { "name": "name" },
            { "name": "position" },
            { "name": "office" },
            { "name": "salary" }
        ],
        
        "order": [[1, 'asc']]
    } );
     
  
    // Add event listener for opening and closing details
    $('#example tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr );
 
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child( format() ).show();
            tr.addClass('shown');
        }
    } );
  
  $('#get-open').click(function(){
    console.log(table.rows().getOpenChildren().toArray());
    $('#ids').text(table.rows().getOpenChildren().toArray().join(', '));
  });
 
} );
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers