javascript - extjs 网格编辑器前进到下一列

标签 javascript extjs

我正在尝试制作一个网格编辑器,它会在第一列中键入 5 个字符后自动前进到下一列。我已经将我认为正确的代码放在一起,但所选列不断跳回到第一列并清除输入的数据。

这是我正在使用的网格:

Ext.create('Ext.grid.Panel', {
    title: 'idNumbers',
    store: Ext.data.StoreManager.lookup('priceStore'),
    plugins: [Ext.create('Ext.grid.plugin.RowEditing', 
    {
        clicksToEdit: 1,
        pluginId: 'idNumberGridEditor'
    })],
    columns: [
        { 
            header: 'Name',  
            dataIndex: 'idNumber',
            editor: {
                allowBlank: false,
                xtype: 'combobox',
                store: Ext.data.StoreManager.lookup('idNumberStore'),
                displayField: 'idNumber',
                valueField: 'idNumber',
                typeAhead: true,
                allowBlank: false,
                forceSelection: true,
                enableKeyEvents: true,
                listeners: {
                    keyup: function(combo, e, eOpts) {
                        if(combo.getValue().length==5)
                        {
                            //move to next control
                            if(!this.nowFive)
                            {
                                editPlugin = this.up().editingPlugin;
                                curRow = editPlugin.context.rowIdx;
                                curCol = editPlugin.context.colIdx;
                                editPlugin.startEdit(curRow, curCol + 1);
                                this.nowFive = true;
                            }
                        }
                        else
                        {
                            this.nowFive = false;
                        }                 
                   }
                }
            }
        },
        { 
            header: 'Phone', 
            dataIndex: 'price',
            editor: {
                allowBlank: false,
                 xtype: 'numberfield'
            }
        }
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody(),
    listeners: {
        afterrender: function() {
            console.log(this);
            //this.editor.startEdit(1,1);
        }
    }
});

这是完整的例子:http://jsfiddle.net/cFD9W/5/

最佳答案

startEdit将重置编辑状态(它旨在与 completeEditcancelEdit 结合使用。您在这里想要的只是关注下一个字段,这样编辑状态将由插件正确处理。

本着这种精神 (updated fiddle),这是对您的听众的重写:

keyup: function(combo, e, eOpts) {
    if(combo.getValue().length==5) {
        //move to next control
        if(!this.nowFive) {
            var editPlugin = this.up().editingPlugin,
            editor = editPlugin.getEditor(), // Ext.grid.RowEditor
            curCol = editPlugin.context.colIdx,
            currentField = editor.getEditor(curCol),
            nextField = editor.getEditor(curCol + 1);
            if (currentField) {
                // ensure the combo is collapsed when the field is blurred
                currentField.triggerBlur();
            }
            if (nextField) {
                // startEdit will reset the edit state... What we need
                // is simply to focus the field, the value will be
                // updated when the user clicks the "update" button.
                nextField.focus();
            }
            this.nowFive = true;
        }
    } else {
        this.nowFive = false;
    }                 
}

最后,正如 Akori 所说,如果您将 forceSelection 设置为 true,组合值将被强制为商店中已经存在的组合值,这可能不是您想要的。

关于javascript - extjs 网格编辑器前进到下一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691746/

相关文章:

javascript - 基本事件监听器抛出错误 ('undefined is not a function' )

extjs - 如何正确取消商店过滤请求

javascript - 如何在 Ajax Post 中重定向?

javascript - Javascript 如何不打印我的文本框按钮并打印我的照片?

javascript - 如何在没有事件的情况下获得鼠标位置(不移动鼠标)?

javascript - ExTJS:如何获取所有可点击和可编辑的组件(按钮、触发器、文本字段等)?

javascript - ExtJS 传递 store.sync() 上的所有字段

css - ExtJS 4 将 CSS 属性添加到操作列

javascript - ExtJS 底层验证

javascript - 删除 Div 不起作用