DataTable 1.10.20 + BS4

by acjackson911

HTML

<script src="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/fh-3.1.6/r-2.2.3/rg-1.1.1/datatables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/fh-3.1.6/r-2.2.3/rg-1.1.1/datatables.min.css">
<div class="page-header">
  <h1>Example page header <small>Subtext for header</small></h1>
</div>

<div>
  <table class="table table-bordered table-striped table-hover" id="mytable">
    <thead>

      <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>
        <th class='col-dataGroup3'>
          Some Col 1
        </th>
        <th class='col-dataGroup3'>
          Some Col 2
        </th>
        <th class='col-dataGroup3'>
          Some Col 3
        </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>
        <td>
          x
        </td>
        <td>
          y
        </td>
        <td>
          z
        </td>

      </tr>
      <tr>
        <td>
          2
        </td>
        <td>
          456
        </td>
        <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',
    },
    {
      extend: 'columnToggle',
      text: 'DataGroup 3',
      columns: '.col-dataGroup3',
    },
  ],
  // enable x-scrolling
  //"scrollX": true,
  fixedHeader: true
});

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