JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/u/bs-3.3.6/dt-1.10.12/datatables.min.css">
<script src="https://cdn.datatables.net/u/bs-3.3.6/dt-1.10.12/datatables.min.js"></script>
<table id="example" class="table table-striped table-bordered table-condensed" 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>
<td>Edinburgh</td>
...
JavaScript
$(document).ready(function () {
var table = $('#example').DataTable({
scrollX: true
});
// Create filter row
var filterTr = $('<tr></tr>');
table.columns().every(function (colIndex, tLoopCounter, cLoopCounter) {
var that = this, filterTd = null;
if (this.header().cellIndex >= 0) {
filterTd = $('<td></td>');
if (colIndex == 2) {
var selectOptions = table.rows().data().pluck(colIndex).unique();
var select = $('<select id="office" class="chosen-select input-sm" />')
select.append('<option value="" />');
$.map(selectOptions, function (el, idx) {
var option = '<option value="' + el + '">' + el + '</option>';
select.append(option);
});
filterTd.append(select);
$('select#office', filterTd).chosen({
disable_search_threshold: 10,
allow_single_deselect: true,
width: "100%"
});
$('select#office', filterTd).on('change', function () {
var newValue = this.value;
if (that.search() !== newValue) {
that
.search(newValue)
.draw();
}
});
}
filterTr.append(filterTd);
}
});
if ($('input, select', filterTr).length > 0)
$('tr:last', table.table().header()).after(filterTr);
});