微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 在可编辑的网格中,如何在选择项目时使Ext组合框立即完成编辑模式?

我已经使用CellEditing插件配置了一个可编辑的Ext JS 4网格.网格中的某些单元格具有文本字段编辑器,少数单元格使用组合框编辑器.这一切都很好,但我对组合框编辑器的认行为有一个小问题.

基本上,在编辑具有组合框编辑器的单元格时,如果使用鼠标从下拉列表中选择项目,则该单元格的“编辑”模式不会完成.换句话说,单元格不会立即退出编辑模式并被标记为脏.相反,它只会处于编辑模式,直到您单击页面上的其他位置.

我认为Sencha将此作为组合框编辑器的认行为是不寻常的,但我不会抱怨.我只想知道如何能够选择一个组合框项并立即使单元格退出编辑模式,但我不知道在哪里定义此自定义行为.

这里有一个小例子JS小提琴:

http://jsfiddle.net/FFwkM/

下面复制的代码用于后代:

var stateStore = Ext.create('Ext.data.Store', {
    fields: ['name'],
    data : [
        {"name":"Alabama"},
        {"name":"Alaska"},
        {"name":"Arizona"}
    ]
});

var gridStore = Ext.create('Ext.data.Store', {
    fields:['firstName', 'state'],
    data:{'items':[
        {"firstName":"Lisa", "state":"Alabama"},
        {"firstName":"Bart", "state":"Alabama"},
        {"firstName":"Homer", "state":"Alabama"},
        {"firstName":"Marge", "state":"Arizona"}
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: gridStore,
    columns: [{
        header: 'First Name',  dataIndex: 'firstName', flex: 1, editor: 'textfield'
    }, {
        header: 'State', dataIndex: 'state', flex: 1, editor: {
            xtype: 'comboBox', store: stateStore, queryMode: 'local', displayField: 'name', valueField: 'name'
        }
    }],
    selType: 'cellmodel',
    plugins: [{
        ptype: 'cellediting',
        clicksToEdit: 2
    }],
    height: 150,
    width: 200,
    renderTo: Ext.getBody()
});

解决方法:

实现所需行为的一种方法是在组合框上为select事件添加侦听器,然后在处理程序中触发blur事件.例:

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: gridStore,
    columns: [{
        header: 'First Name',  dataIndex: 'firstName', flex: 1, editor: 'textfield'
    }, {
        header: 'State', dataIndex: 'state', flex: 1, editor: {
            xtype: 'comboBox', store: stateStore, queryMode: 'local', displayField: 'name', valueField: 'name',
            listeners: {
                select: function(combo, recs, opts){
                    combo.fireEvent('blur'); //<------
                }
            }
        }
    }],
    selType: 'cellmodel',
    plugins: [{
        ptype: 'cellediting',
        clicksToEdit: 2
    }],
    height: 150,
    width: 200,
    renderTo: Ext.getBody()
});

工作叉在这里http://jsfiddle.net/Zd5QM/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐