ExtJS 4,不同的行字段 [英] ExtJS 4, Different rows fields

查看:158
本文介绍了ExtJS 4,不同的行字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

$ b $可以在网格中具有按行列定义b

  id |名称|选项
======================================
int |字符串|组合框(1,2,3)
int |字符串|组合框(1,2,3,4,5)
int |字符串|组合框(1,2,3)
int |字符串| combobox(5,6,7)

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

解决方案

你有几种选择这里。但首先要确定为什么你首先需要一个组合框。你是否需要

<1>标准单元格编辑器插件在单击单元格内时被激活,或者

2)您是否需要使用每行中始终激活的组合框渲染您的单元格?如果你的答案是1),那么你需要做两件事:
a)重写默认的CellEditing插件,以允许每行上的不同组合框。默认实现缓存编辑器配置每列一次。
b)提供一个函数,该函数在您的单元格调用getEditor()时返回编辑器配置。



我将在下面提供代码。



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






附录:

选项1的代码)

列配置 -

  {text:'我的组合列',
datIndex:'someStoreField',
getEditor:function (记录){
console.log('in get editor');
返回myFunctionToDetermineEditorConfig(记录);
}
}

CellEditor覆盖。 'this'是对Grid的引用

  this.plugins = [
Ext.create('Ext.grid。 plugin.CellEditing',{
clicksToEdit:1,
//覆盖原来允许列中的多个编辑器
getEditor:function(record,column){
var editor =如果(!编辑器instanceof Ext.grid.CellEditor){$ b $($编辑器){
返回false;
}
) b editor = new Ext.grid.CellEditor({
// editorId:editorId,
field:editor,
ownerCt:this.grid
});
}其他{
editor.ownerCt = this.grid;
}
editor.editingPlugin = this;
editor.isForTree = this.grid.isTree;
editor.on({
scope:this,
specialkey:this.onSpecialKey,
complete:this.onEditComplete,
cancelit:this.cancelEdit
});
返回编辑器;
}
})
];


It's possible to have "by-row" columns definition in a Grid?

For example, I need a grid like this:

 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)

The combobox possible values are defined for that column in the initialization...is there a way to define that per row or perhaps some method to define after the rendering?

解决方案

You have several options here. But first decide why you need a combobox in your grid in the first place. Do you need

1) a standard cell editor plugin that gets activated when you click inside the cell, or

2) do you need your cell rendered with a combobox always activated in every row?

If your answer is 1), then you need to do 2 things: a) Override default CellEditing Plugin to allow different comboboxes on each row. The default implementation caches editor config once per column. b) Provide a function that returns editor config when getEditor() is called for your cell.

I'll provide code for these below.

If you answer 2) to the original question then you need a custom component that will render a combobox in your cell. There are two implementations of such a beast, the one I used is Skirtles http://skirtlesden.com/ux/component-column the other is called Its column component http://www.sencha.com/forum/showthread.php?174504-Its.grid.column.Component


Appendix:

Code for Option 1)

Column config -

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

CellEditor override. 'this' is reference to the 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;
                }
        })
    ];

这篇关于ExtJS 4,不同的行字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆