jqGrid navGrid search submit on Enter keypress not working

后端 未结 4 1529
走了就别回头了
走了就别回头了 2020-12-22 00:24

I\'d like to be able to invoke the find button on the search dialog when the \"Enter/Return\" key is pressed. Unfortunately the \'savekey\' option doesn\'t submit the form

相关标签:
4条回答
  • 2020-12-22 00:59

    It seems to me that the problem cam be solved if you replace savekey: [true, 13] option which really not work for searching to the following beforeShowSearch and onClose event handle

    beforeShowSearch: function(form){
        form.keydown(function(e) {
            if (e.which == 13) {
                $(".ui-search", form).click();
            }
        });
    },
    onClose: function(form){
        form.unbind('keydown');
    }
    

    This method will work not only for the single field searching but for advance searching also.

    If you want that the 'Enter' key work only in the input fields you can replace form.keydown to $('.vdata',form).keydown and make the corresponding changes in the unbind.

    0 讨论(0)
  • 2020-12-22 01:02

    This was pretty helpful, but I'm the provided solution isn't quite working for me. I tweaked the code provided and it somewhat works now, but it doesn't appear to be submitting the correct data. Whenever I press the enter key, it submits a "0" in the input box instead of whatever I've actually put in there. For whatever reason it is not posting the searchString. The code I'm using is:

    beforeShowSearch: function(form){
      $(form).keydown(function(e) {
        if (e.keyCode == 13) {
          $("#fbox_cust_grid_search").click();
        }
      });
    },
    onClose: function(form){
      $(form).unbind('keydown');
    }
    

    Do any of you guys have a suggestion as to what might be going on here?

    Edit: Interesting, when I alert something out(anything) right before the .click() method, the data is posted perfectly. Any ideas?

    0 讨论(0)
  • 2020-12-22 01:05

    Try the following code. Works for me:

    beforeShowSearch: function(form){
       $(form).keydown(function(e) {
          if (e.keyCode == 13) {
             setTimeout(function() {
                $("#fbox_cust_grid_search").click();
             }, 200);
          }
       });
       return true;
    },
    onClose: function(form){
       $("#fbox_cust_grid_search").unbind('keydown');
    }
    

    There seems to be an issue when the click method is called too quickly. Giving the grid 200ms to do what it has to do before searching seems to do the trick.

    0 讨论(0)
  • 2020-12-22 01:07

    I had the same problem on FireFox but the above solution worked fine in IE. In order to make it work on Firefox I had to use the focus function instead of click as below:

    beforeShowSearch: function (form) {
                            form.keydown(function (e) {
                                if (e.which == 13) {
                                    $("#fbox_list_search").focus();
                                }
                            });
                        },
    
    0 讨论(0)
提交回复
热议问题