keyup,keypress事件在extjs grd列中没有触发

时间:2013-12-20 05:28:04

标签: extjs extjs3

这是我的网格列

MyColumn3Ui = Ext.extend(Ext.grid.NumberColumn, {
    constructor: function(cfg) {
        cfg = cfg || {};
        MyColumn3Ui.superclass.constructor.call(this, Ext.apply({
            dataIndex: 'ID',
            header: 'name',
            sortable: true,
            width: 75,
            align: 'right',
            id: 'name_col',
            editor: {
                xtype: 'numberfield',
                name: 'ID',
                decimalPrecision: 0,
                allowDecimals: false,
                enableKeyEvents: true,
                allowBlank: false,
                maxLength: 5,
                id: 'col_id'
            }
        }, cfg));
    }
});

这是我尝试触发keyup和keypress事件

 this.col = Ext.getCmp('col_id');
 this.col.blur = blurFun .createDelegate(this, [this.col, 4,""]);
 this.col.keyup = keyupFun.createDelegate(this, [this.col, 4,""]);
 this.col.keypress = keypressFun .createDelegate(this, [this.col, 4,""]);

 blurFun = function(txtField, length, nextField ) {
    alert('blur');
 }
 keyupFun= function(txtField, length, nextField ) {
    alert('keyup ');
 }
 keypressFun = function(txtField, length, nextField ) {
    alert('keypress');
 }

当我点击名称列时,只显示blur提醒。其他事件在我的可编辑ExtJs网格中不会触发。我希望在我的网格列中使用fire keyup,keypress事件

2 个答案:

答案 0 :(得分:0)

要向组件添加事件侦听器,请使用on函数:

this.col.on({
    'blur': function(field) {
        alert('blur');
    },
    scope: this
});

答案 1 :(得分:0)

col模型没有像keyup这样的事件。编辑器中的keyup事件触发

this.col.keyup = keyupFun.createDelegate(this, [this.col, 4,""]); 

更改为

 this.col.editor.keyup = keyupFun.createDelegate(this, [this.col.editor, 4,""]);