2011-05-27 23 views
0

這可見搜索是後續對這個問題Possible to make jqGrid Search Box Stay on Page?JQ網格上的Enter鍵,如果搜索框總是

我找到方向製作上的回車鍵的網格搜索,如果搜索框被擰開,然後以正常方式關閉,但是,如果搜索表單始終可見,是否可以使回車鍵觸發搜索?

編輯爲我們之間的字面意義,我會怎麼去做呢?

+1

是的,這是可能的。你沒有問過如何 – MLS 2011-05-27 14:50:14

回答

1

你有可能。我想你仍然使用jqGrid 3.8.2。所以我會在我的答案中使用該版本。

該解決方案的主要思想可以在the answer中找到。要更加小心的beforeShowSearch代碼應該是一個小擴展:提前搜索對話框中

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 demo),並且始終是在網格的對話框中(見another demo)。

修訂:用jQuery 1.8酮原料應使用$._data($('.vdata',$form)[0], 'events');而不是$('.vdata',$form).data('events')獲得網格的所有事件的列表。