jq Grid Search on Enter if Search Box is always visible on page

北慕城南 提交于 2020-01-17 05:42:11

问题


This is a followup to this question Possible to make jqGrid Search Box Stay on Page?

I found directions for making the grid search on the enter key if the search box is being popped open and then closing in the normal fashion, but, is it possible to make the enter key trigger a search if the search form is always visible?

Edit for the literal among us, and how would I go about doing so please?


回答1:


You it is possible. I suppose that you still use jqGrid 3.8.2. So I will use the version in my answer.

The main idea of the solution you can find in the answer. To be more careful the code of beforeShowSearch should be a little extended:

beforeShowSearch: function($form) {
    // because beforeShowSearch will be called on all open Search Dialog,
    // but the old dialog can be only hidden and not destroyed
    // we test whether we already bound the 'keydown' event
    var events = $('.vdata',$form).data('events'), event;
    for (event in events) {
        if (events.hasOwnProperty(event) && event === 'keydown') {
            return;
        }
    }
    $('.vdata',$form).keydown( function( e ) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (e.which == 13) { // save
            //$(".ui-search", $form).click();
            grid[0].SearchFilter.search();
        }
    });
}

The way works in the advance searching dialog (see the demo) and in the dialog which is always over the grid (see another demo).

UPDATED: Starting with jQuery 1.8 one should use $._data($('.vdata',$form)[0], 'events'); instead of $('.vdata',$form).data('events') to get the list of all events of the grid.



来源:https://stackoverflow.com/questions/6153746/jq-grid-search-on-enter-if-search-box-is-always-visible-on-page

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