Skip to content

Instantly share code, notes, and snippets.

@elidrissidev
Created January 30, 2021 18:35
Show Gist options
  • Save elidrissidev/342834b7e990a8264bcfb593e5d25ab7 to your computer and use it in GitHub Desktop.
Save elidrissidev/342834b7e990a8264bcfb593e5d25ab7 to your computer and use it in GitHub Desktop.
Datatables order with top cells & search with bottom cells
$('table').DataTable({
orderCellsTop: true,
ajax: {
url: 'http://jsonplaceholder.typicode.com/users',
dataSrc: '',
},
columns: [
{ data: 'id' },
{ data: 'name' },
{ data: 'username' },
{ data: 'email' },
{ data: 'phone' },
],
initComplete: function () {
this.api().columns().every(function () {
const column = this;
$(this.header().dataset.searchInput).on('change clear', function () {
if (column.search() !== this.value) {
column.search(this.value).draw();
}
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment