JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table width="100%" class="table table-striped table-bordered dt-responsive nowrap" id="example" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>ZIP / Post code</th>
<th>Country</th>
</tr>
</thead>
</table>
JavaScript
var table;
$(document).ready(function() {
table = $('#example').DataTable({
serverSide: true,
ordering: false,
searching: false,
ajax: function(data, callback, settings) {
var out = [];
for (var i = data.start, ien = data.start + data.length; i < ien; i++) {
out.push([i + '-1' , i + '-2', i + '-3', i + '-4', i + '-5']);
}
setTimeout(function() {
callback({
draw: data.draw,
data: out,
recordsTotal: 5000,
recordsFiltered: 5000
});
}, 50);
},
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>');
select.appendTo( $(column.header()).empty() )
select.on( 'click', function(e) {
e.stopPropagation();
} );
select.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
},
});
table.on('draw', function () {
table.columns().indexes().each( function ( idx ) {
var select = $(table.column( idx ).header()).find('select');
if ( select.val() === '' ) {
select
.empty()
.append('<option value=""/>');
table.column(idx, {search:'applied'}).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' );
} );
}
} );
} );
});