Created
January 30, 2021 18:35
-
-
Save elidrissidev/342834b7e990a8264bcfb593e5d25ab7 to your computer and use it in GitHub Desktop.
Datatables order with top cells & search with bottom cells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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