JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/select/1.2.0/css/select.dataTables.min.css">
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js"></script>
<table border="0" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>Minimum salary:</td>
<td><input type="text" id="min" name="min"></td>
</tr>
<tr>
<td>Maximum salary:</td>
<td><input type="text" id="max" name="max"></td>
</tr>
</tbody></table><table id="example" class="display" 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>9.6.50.31</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>9.5.370.136</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New...
JavaScript
$(document).ready(function() {
var table = $('#example').DataTable();
// Event listener to the two range filtering inputs to redraw on input
$('#min, #max').keyup( function() {
table.draw();
});
});
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = parseFloat( $('#min').val(), 10 );
var max = parseFloat( $('#max').val(), 10 );
var value = parseFloat( data[5] ) || 0; // use data for the salary column
if ( ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && value <= max ) ||
( min <= value && isNaN( max ) ) ||
( min <= value && value <= max ) )
{
return true;
}
return false;
}
);