简体   繁体   English

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

[英]In an editable grid, how to make an Ext combo box immediately finish edit mode when selecting an item?

I have configured an Ext JS 4 grid to be editable by utilising the CellEditing plugin. 我已经使用CellEditing插件配置了一个可编辑的Ext JS 4网格。 Some cells in the grid have a textfield editor, and a few use a combo box editor. 网格中的某些单元格具有文本字段编辑器,少数单元格使用组合框编辑器。 It all works great, but I have a small problem with the default behaviour of combo box editors. 这一切都很好,但我对组合框编辑器的默认行为有一个小问题。

Basically, when editing a cell that has a combo box editor, if you select an item from the dropdown with your mouse, the "edit" mode of that cell doesn't finish. 基本上,在编辑具有组合框编辑器的单元格时,如果使用鼠标从下拉列表中选择项目,则该单元格的“编辑”模式不会完成。 In other words, the cell doesn't immediately go out of edit mode and get marked as dirty. 换句话说,单元格不会立即退出编辑模式并被标记为脏。 Instead, it will just sit there in edit mode until you go and click somewhere else on the page. 相反,它只会处于编辑模式,直到您单击页面上的其他位置。

I think it is unusual that Sencha has made this the default behaviour for combo box editors, but I won't complain. 我认为Sencha将此作为组合框编辑器的默认行为是不寻常的,但我不会抱怨。 I would just like to know how to be able to select a combo box item and immediately take the cell out of edit mode, but I have no idea where to define this custom behaviour. 我只想知道如何能够选择一个组合框项并立即使单元格退出编辑模式,但我不知道在哪里定义此自定义行为。

Here's a small example JS fiddle to play with: 这里有一个小例子JS小提琴:

http://jsfiddle.net/FFwkM/ http://jsfiddle.net/FFwkM/

Code copied below for posterity: 下面复制的代码用于后代:

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()
});

One way of achieving the desired behaviour is to add a listener for the select event on your combobox, then fire the blur event in the handler. 实现所需行为的一种方法是在组合框上为select事件添加侦听器,然后在处理程序中触发blur事件。 Example: 例:

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()
});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM