DataTable 1.10.10 + Bootstrap

Buttons Test

by acjackson911

HTML

<link rel="stylesheet" href="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/b-1.3.1/b-colvis-1.3.1/fh-3.1.2/r-2.1.1/rg-1.0.0/datatables.min.css">
<script src="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/b-1.3.1/b-colvis-1.3.1/fh-3.1.2/r-2.1.1/rg-1.0.0/datatables.min.js"></script>
<div class="page-header">
  <h1>Example page header <small>Subtext for header</small></h1>
</div>

<div>
  <table class="table table-striped table-hover" id="mytable">
    <thead>
      <tr>
        <th id='info' scope="col" colspan='2' class='col-info'>
          Info
        </th>
        <th id='dataGroup1' colspan='3' class='col-dataGroup1'>
          DataGroup 1
        </th>
        <th id='dataGroup2' colspan='4' class='col-dataGroup2'>
          DataGroup 2
        </th>
      </tr>
      <tr>
        <th class='col-info'>
          Line #
        </th>
        <th class='col-info'>
          EmpID
        </th>
        <th class='col-dataGroup1'>
          SID
        </th>
        <th class='col-dataGroup1'>
          First&#160;Name
        </th>
        <th class='col-dataGroup1'>
          Last&#160;Name
        </th>
        <th class='col-dataGroup2'>
          Type
        </th>
        <th class='col-dataGroup2'>
          App ID
        </th>
        <th class='col-dataGroup2'>
          Batch ID
        </th>
        <th class='col-dataGroup2'>
          Correlation&#160;ID
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          1
        </td>
        <td>
          12
        </td>
        <td>
          456
        </td>
        <td>
          Barney
        </td>
        <td>
          Gumble
        </td>
        <td>
          P Adj
        </td>
        <td>
          1
        </td>
        <td>
          1
        </td>
        <td>
          1
        </td>
      </tr>
      <tr>
        <td>
          2
        </td>
        <td>
          456
        </td>
        <td>
          7890
        </td>
      ...

JavaScript

$('#mytable').DataTable({
  "dom": 'lBfrtip',

  buttons: [{
      extend: 'columnToggle',
      text: 'Info',
      columns: '.col-info',
    },

    {
      extend: 'columnToggle',
      text: 'DataGroup 1',
      columns: '.col-dataGroup1',
    },

    {
      extend: 'columnToggle',
      text: 'DataGroup 2',
      columns: '.col-dataGroup2',
    },
  ],
  // enable x-scrolling
  "scrollX": true,
});

$('div.dataTables_length select[name="mytable_length"]').on('change', function(){
var len = $('#mytable').DataTable().page.len();
    alert(len);
});