DataTables

DataTables Examples

by Samuel Guimarães

HTML

<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<div class="container">
  <i class="fa fa-angle-up" aria-hidden="true"></i>
  <table id="example" class="table table-striped" cellspacing="0" width="100%">
    <thead>
      <tr>
        <th>Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Age</th>
        <th>Start date</th>
        <th>Salary</th>
      </tr>
    </thead>
    <tfoot>
      <tr>
        <th>Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Age</th>
        <th>Start date</th>
        <th>Salary</th>
      </tr>
    </tfoot>
    <tbody>
      <tr>
        <td>Tiger Nixon</td>
        <td>System Architect</td>
        <td>Edinburgh</td>
        <td>61</td>
        <td>2011/04/25</td>
        <td>$320,800</td>
      </tr>
      <tr>
        <td>Garrett Winters</td>
        <td>Accountant</td>
        <td>Tokyo</td>
        <td>63</td>
        <td>2011/07/25</td>
        <td>$170,750</td>
      </tr>
      <tr>
        <td>Ashton Cox</td>
        <td>Junior Technical Author</td>
        <td>San Francisco</td>
        <td>66</td>
        <td>2009/01/12</td>
        <td>$86,000</td>
      </tr>
      <tr>
        <td>Cedric Kelly</td>
        <td>Senior Javascript Developer</td>
    ...

CSS

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,400,600);
body {
  font-family: "Open Sans", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-size: 14px;
  line-height: 1.42857;
  color: #222;
  background-color: #fff;
}

table.dataTable tfoot {
  display: none;
}

div.dataTables_wrapper div.dataTables_paginate {
  text-align: left;
}

div.dataTables_wrapper div.dataTables_info {
  text-align: right;
}

div.dataTables_wrapper .dataTables_length {
  text-align: right;
  padding-left: 10px;
}

div.dataTables_wrapper .dataTables_length select,
div.dataTables_wrapper .dataTables_length .btn {
  width: 66px;
}

div.dataTables_wrapper div.dataTables_filter .form-control {
  width: 514px;
  height: 34px;
}

table.dataTable thead .sorting:after,
table.dataTable thead .sorting:before,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_desc:after,
table.dataTable thead .sorting_desc:before,
table.dataTable thead .sorting_asc_disabled:after,
table.dataTable thead .sorting_asc_disabled:before,
table.dataTable thead .sorting_desc_disabled:after,
table.dataTable thead .sorting_desc_disabled:before {
  display: inline-block;
  font: normal normal normal 14px/1 FontAwesome;
  font-size: 19px;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

table.dataTable thead .sorting:before {
  opacity: 0.3;
  content: "\f106";
  position: absolute;
  top: 3px;
  right: 8px;
}

table.dataTable thead .sorting:after {
  opacity: 0.3;
  content: "\f107";
  position: absolute;
  top: 13px;
  right: 8px;
}

table.dataTable thead .sorting_asc:after {
  opacity: 0.8;
  content: "\f107";
  top: 13px;
}

table.dataTable thead .sorting_desc:after {
  opacity: 0.8;
  content: "\f106";
  position: absolute;
  top: 3px;
  right: 8px;
}

.table>thead>tr>td,
.table>thead>tr>th {
  font-family: "Open Sans", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight:...

JavaScript

$(document).ready(function() {
  $('#example').dataTable({
    "sPaginationType": "full_numbers",
    "dom": '<"row"<"col-sm-12 filter"<"pull-right"l><"pull-right"f>>><"row"<"col-sm-12"t>><"row"<"col-sm-6 pages"p><"col-sm-6 info"i>>'
  });
  $('.dataTables_filter input').attr("placeholder", "Filter");
  $(".dataTables_filter label").contents().filter(function() {
    return this.nodeType === 3;
  }).wrap('<div class="sr-only" />');
  $(".dataTables_length label").contents().filter(function() {
    return this.nodeType === 3;
  }).wrap('<div class="sr-only" />');
  $(".dataTables_length select").selectpicker();
  $(".dataTables tfoot").remove();
});