Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
893 views
in Technique[技术] by (71.8m points)

how to enable enter in jqgrid advanced search window

Pressing search button in jqgrid toolbar opens advanced search window. Pressing enter key does not start seach. To start search, search button needs to be clicked.

How to allow enter key press to start search like in clicking in search button ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To implement search on Enter key one have to implement binding to keydown event to any input fields and force searching on Enter. If you include jQuery UI jquery-ui.min.js then you can use $.ui.keyCode.ENTER instead of 13 for the better readability of the code.

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 demonstrate the code live.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...