mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Require >=3 chars for datatable search
Performing a search with < 3 chars is not generally fruitful
This commit is contained in:
parent
64ceaf50f4
commit
7541f5818c
1 changed files with 21 additions and 0 deletions
|
|
@ -8,4 +8,25 @@ $(function () {
|
|||
|
||||
$('.datatable:not([data-source])').DataTable();
|
||||
|
||||
$('.datatable').on('init.dt', function (e, settings, json) {
|
||||
var datatableApi = $(this).dataTable().api();
|
||||
// Thanks to cale_b: https://stackoverflow.com/u/870729
|
||||
// Stack Overflow question: https://stackoverflow.com/q/5548893
|
||||
// Stack Overflow answer: https://stackoverflow.com/a/23897722
|
||||
// Grab the datatables input box and alter how it is bound to events
|
||||
$(".dataTables_filter input")
|
||||
.unbind() // Unbind previous default bindings
|
||||
.bind("input", function(e) { // Bind our desired behavior
|
||||
// If the length is 3 or more characters, or the user pressed ENTER, search
|
||||
if(this.value.length >= 3 || e.keyCode == 13) {
|
||||
// Call the API search function
|
||||
datatableApi.search(this.value).draw();
|
||||
}
|
||||
// Ensure we clear the search if they backspace far enough
|
||||
if(this.value == "") {
|
||||
datatableApi.search("").draw();
|
||||
}
|
||||
return;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue