datatables.mark.js global search example
This fiddle demonstrates how to use julmot/mark.js and julmot/datatables.mark.js for a global search using DataTables
by fnguyen20
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/united/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css">
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/mark.js/8.6.0/jquery.mark.min.js"></script>
<script src="https://cdn.jsdelivr.net/datatables.mark.js/2.0.0/datatables.mark.min.js"></script>
<h2><a href="https://github.com/julmot/datatables.mark.js/" target="_blank">datatables.mark.js</a> global search example</h2>
<div class="panel panel-default">
<div class="panel-heading">Search</div>
<div class="panel-body">
<table class="datatables-table table table-striped table-hover table-bordered">
<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>
...
CSS
body {
margin: 15px;
}
div.search span {
display: block;
}
div.panel {
margin-bottom: 15px;
}
div.panel .panel-body p:last-child {
margin-bottom: 0;
}
/**
* Styles for datatables.mark.js
*/
mark {
padding: 0;
background: #f1c40f;
}
JavaScript
$(function() {
// Initialize DataTables
$('.datatables-table').DataTable({
// Enable mark.js search term highlighting
mark: true
});
});