我最終不得不綁定一個新的點擊並將'輸入'監聽器綁定到'from'和'to'過濾器輸入,然後使用bindFirst
在yii.gridView.js
之前綁定它,並返回false以阻止它傳播。像這樣:
/**
* Need to bind first to stop yii.gridView.js triggering filter change
*/
$filterInputs.bindFirst('change.yiiGridView keydown.yiiGridView', function() {
if (event.type === 'keydown') {
// enter button
if (event.keyCode == 13) {
$btn.trigger('click');
return false;
}
} else return false;
});
/**
* Bind to the front of the event listener queue
*/
$.fn.bindFirst = function(name, fn) {
var elem, handlers, i, _len;
this.bind(name, fn);
for (i = 0, _len = this.length; i < _len; i++) {
elem = this[i];
handlers = jQuery._data(elem).events[name.split('.')[0]];
handlers.unshift(handlers.pop());
}
};