How to enable input in advanced search box jqgrid
Clicking the search button on the jqgrid toolbar opens the advanced search box. Pressing the enter key does not start. To start searching, you need to click the search button.
How do I allow keyboard input to be pressed to start searching, for example by clicking the search button?
+3
source to share
2 answers
To implement a search by key, Enteryou need to implement an event binding keydown
to any input fields and force a search on Enter. If you include jQuery UI jquery-ui.min.js
you can use $.ui.keyCode.ENTER
13 instead for better code readability.
The code can be like
$.extend($.jgrid.search, {
// ... some other default which you use
afterRedraw: function (p) {
var $form = $(this), formId = this.id, // fbox_list
bindKeydown = function () {
$form.find("td.data>.input-elm").keydown(function (e) {
if (e.which === $.ui.keyCode.ENTER) {
$(e.target).change();
$("#" + $.jgrid.jqID(formId) + "_search").click();
}
});
},
oldOnChange = p.onChange,
myOnChange = function (param) {
var $input = $form.find("td.data>.input-elm"), events;
oldOnChange.call(this, param);
if ($input.length > 0) {
events = $._data($input[0], "events");
if (events && !events.keydown) {
bindKeydown();
}
}
};
p.onChange = myOnChange;
bindKeydown.call(this);
}
});
The demo demonstrates the code live.
+6
source to share