DataTables

DataTables Examples

HTML

<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.1.0/css/buttons.dataTables.min.css">
<script src="https://cdn.datatables.net/buttons/1.1.0/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.0/js/buttons.colVis.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.0/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.0/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.10/css/dataTables.bootstrap.css">
<script src="https://cdn.datatables.net/1.10.10/js/dataTables.bootstrap.js"></script>
<script src="http://cdn.datatables.net/buttons/1.1.0/js/buttons.bootstrap.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.0/js/buttons.bootstrap.js"></script>
<span id="test"></span>
<table id="example">
        <thead>
            <tr>
                <th>Seq.</th>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>2</td>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>22</td>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
  ...

CSS

#colvis {
  border: 2px solid red;
  display: inline-block;
  float: none;
}
.pagination, .dataTables_paginate {
  display: inline;
}

#test {
  border:4px solid red;
}

JavaScript

var org_buildButton = $.fn.DataTable.Buttons.prototype._buildButton;
 $.fn.DataTable.Buttons.prototype._buildButton = function(config, collectionButton) {
     var button = org_buildButton.apply(this, arguments);
     $(document).one('init.dt', function(e, settings, json) {
        if (config.container && $(config.container).length) {
           $(button.inserter[0]).detach().appendTo(config.container)
        }
    })    
    return button;
 }

var table = $('#example').DataTable({
 dom : "B<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>",
 "buttons": [
         {
            extend: 'copyHtml5',
            container: '#test'
         },   
        'excelHtml5',
        'csvHtml5',     
          {
            extend: 'colvis',
            postfixButtons: [ 'colvisRestore' ],
            container : '#colvis',
            columns: '0,1,2,3,4,5'
        }
      ],
    language: {
        buttons: {
            colvis: 'Change columns'
        }
    }
})