Skip to content

Instantly share code, notes, and snippets.

@surferxo3
Last active May 13, 2020 13:05
Show Gist options
  • Save surferxo3/d1b4b21dffc4feebea926f62819ac5e5 to your computer and use it in GitHub Desktop.
Save surferxo3/d1b4b21dffc4feebea926f62819ac5e5 to your computer and use it in GitHub Desktop.
Perform global search on DataTables either via enter keypress or button click
// reset search on input clear / special 'x' click
$('.dataTables_filter input')
.unbind()
.bind('keyup input', function (e) { // works both for keyboard input and for special 'x' click mouse input
var searchTerm = $(this).val().trim();
if (searchTerm === '' || e.keyCode === 13) {
prodFilesTable.search(searchTerm).draw();
}
});
// perform search on button click
$('.search').click(function () {
prodFilesTable.search($('.dataTables_filter input').val()).draw();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment