1

可以在网格中定义“逐行”列吗?

例如,我需要这样的网格:

 id  |   name    |      options
======================================
int  |  string   |  combobox(1,2,3)
int  |  string   |  combobox(1,2,3,4,5)
int  |  string   |  combobox(1,2,3)
int  |  string   |  combobox(5,6,7)

组合框的可能值是在初始化中为该列定义的……有没有办法定义每行的值,或者在渲染后定义一些方法?

4

1 回答 1

3

您在这里有几个选择。但首先要确定为什么首先需要在网格中使用组合框。你需要

1) 一个标准的单元格编辑器插件,当您在单元格内单击时会被激活,或者

2)您是否需要在每一行中始终激活组合框来呈现您的单元格?

如果您的答案是 1),那么您需要做 2 件事: a) 覆盖默认的 CellEditing 插件以允许在每一行上使用不同的组合框。默认实现每列缓存一次编辑器配置。b) 提供一个在为您的单元格调用 getEditor() 时返回编辑器配置的函数。

我将在下面提供这些代码。

如果您对原始问题回答 2),那么您需要一个自定义组件,该组件将在您的单元格中呈现一个组合框。这样的野兽有两种实现,我使用的一种是 Skirtles http://skirtlesden.com/ux/component-column,另一种称为它的列组件 http://www.sencha.com/forum/showthread.php ?174504-Its.grid.column.Component


附录:

选项 1) 的代码

列配置 -

{  text: 'My Combo Column',
   datIndex: 'someStoreField',
   getEditor:function(record){
       console.log('in get editor');
       return myFunctionToDetermineEditorConfig(record);
   }
}

单元格编辑器覆盖。'this' 是对 Grid 的引用

this.plugins = [
        Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit:1,
            //override original to allow for multiple editors in a column
            getEditor:function (record, column) {
                    var editor = column.getEditor(record);
                    if (!editor) {
                        return false;
                    }
                    if (!(editor instanceof Ext.grid.CellEditor)) {
                        editor = new Ext.grid.CellEditor({
                            //editorId:editorId,
                            field:editor,
                            ownerCt:this.grid
                        });
                    } else {
                        editor.ownerCt = this.grid;
                    }
                    editor.editingPlugin = this;
                    editor.isForTree = this.grid.isTree;
                    editor.on({
                        scope:this,
                        specialkey:this.onSpecialKey,
                        complete:this.onEditComplete,
                        canceledit:this.cancelEdit
                    });
                    return editor;
                }
        })
    ];
于 2012-09-25T23:13:33.793 回答