2012-09-08 25 views
0

我已經寫了下面的代碼使用jQuery:將函數綁定到jQGrid過濾的文本框?

$('input[type="text"]').keyup(
    function (event) { 
     // Allow: backspace, delete, tab, escape, and enter 
     if (event.keyCode != 68 && event.keyCode != 186) return; 
     var textbox = $(this); 
     var clickAttr = textbox.attr('click'); 
     if (clickAttr != undefined && clickAttr.indexOf('NumericTextBoxKeyPress') > -1) return; 
     var insertedValue = textbox.val(); 
     insertedValue = insertedValue.replace(/a/g, 'SampleA'); 
     insertedValue = insertedValue.replace(/b/g, 'SampleB'); 
     textbox.val(insertedValue); 
    } 
); 

這是正常的文本框OK,但上面的代碼不會對jqGrid的過濾的文本框的工作!

Bind a function to jQGrid filtering's textboxes

能否請你指導我,我怎麼可以綁定一個KEYUP功能的jqGrid過濾的文本框?

回答

1

如果你有網格,並希望在搜索工具欄的一個指定的輸入字段綁定事件時,可以使用searchoptionscolModel的相應列的dataEvents(見here)。代碼示例請參見the answer

如果你需要一些事件綁定就像keyup電網的搜索工具欄的所有輸入字段,你可以做到以下幾點:

var $grid = $("#list"); // the grid 

// create the grid 
$grid.jqGrid({ 
    //... jqGrid options 
}); 

// create the searching toolbar with the line like 
$grid.jqGrid('filterToolbar', {defaultSearch: 'cn'}); 

// get all input fields of the searching toolbar 
var $toolbarRow = $grid.closest(".ui-jqgrid-view") 
         .find(".ui-jqgrid-htable .ui-search-toolbar"); 

// make the binding of all input fields to the event which you need 
$toolbarRow.find('input[type="text"]').keyup(function (e) { 
    // the code of your event handler 
});