how to enable enter in jqgrid advanced search window

此生再无相见时 提交于 2019-11-28 12:44:12
Oleg

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!