0

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?

Community
  • 1
  • 1
Amy Anuszewski
  • 1,843
  • 17
  • 30

1 Answers1

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798