如何使用另一个网格为网格中的特殊单元格创建单元格编辑器,并在ExtJs中从中选择值?

时间:2014-12-22 07:49:33

标签: javascript extjs extjs4.2 tablecelleditor

我正在尝试使用网格创建编辑器,现在我有了这样的变体:

var panelWithGrid = Ext.create('Ext.grid.Panel', {
    store: cellEditorGridStore,
    autoScroll: true,
    width: 300,
    height: 200,
    sortable: true,
    title: "My Editor",
    ...
    columns: [
        {
            dataIndex: "first",
            width: "13%",
            text: "First"
        },
        {
            dataIndex: "second",
            width: "87%",
            text: "Second"
        }
    ],
    bbar: [
        {
            xtype: "button",
            text: "change value of cell",
            handler: function(){
                //close action + inserting of selected value from one grid to another?
            }
        },
        {
            xtype: "button",
            text: "close editor",
            handler: function(){
                //normal close action? tried to hide, that works bad.
            }
        }
    ]
});
var myOwnCellEditor = Ext.create('Ext.grid.CellEditor', {
    autoCancel: true,
    closeAction: 'hide',
    field: panelWithGrid
});

此外,我在其中一列

中创建了另一个带有getEditor属性的网格
...
getEditor: function(record){
    if(record.raw.myColumnIndex==="gridEditor"){
        Ext.Ajax.request({
            ...
            async: false,
            success: function(response, options){
                ...//downloading of cellEditorGridStore
            }
    }
    return myOwnCellEditor;
}

所以我对这样的编辑器有很多问题。当我点击要编辑的单元格时出现错误:

Uncaught TypeError: undefined is not a functionext-all.js:38 
Ext.define.startEditext-all.js:38 
Ext.define.showEditorext-all.js:38 
b

当我尝试隐藏编辑器时,第二次显示不正确。你知道更好的方法来实现这样的编辑器吗?

1 个答案:

答案 0 :(得分:2)

已经找到另一种方法来创建小部件以从其他网格中获取价值。 我添加到我的网格

listeners: {
    cellclick: function(gridView,htmlElement,columnIndex,dataRecord){
        if(columnIndex == 1){
            if(dataRecord.data.second){
                ...
                //memorize current dataRecord to change value by using of
                //dataRecord.set("second", new_value) and show my grid-editor
            }
        }
    })
}

这样的决定很有效,但它不是编辑。