GXT 3.x EditorGrid:在每个单元格的基础上选择单元格编辑器类型 [英] GXT 3.x EditorGrid: choose cell editor type on a cell by cell basis

查看:116
本文介绍了GXT 3.x EditorGrid:在每个单元格的基础上选择单元格编辑器类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GXT 3.0 中是否有逐个单元定义编辑器类型的问题?

Is there anyway to define the editor type on a cell by cell basis in GXT 3.0?

我需要创建一个转置表;列成为行,行成为列.在这种情况下,一列(从普通表的角度来看)将具有各种编辑器类型,而一行将具有相同的编辑器类型.

I need to create a transposed table; the column become the row and the row is the column. That being the case, a column (from a normal table point of view) will have various editor type, whereby a row will have identical editor type.

我正在尝试使用以下方法-似乎运行良好,并允许根据数据类型打开编辑器,但是当我单击时;它不会关闭/隐藏编辑器.

I am trying to use following approach - It seems to be working fine, and allow to open up editors based on data type but when i click out; it doesn't close/hide editor.

如果有人能指出正确的方向,我将不胜感激.

I would really appreciate if someone can please point me in right direction.

final GridInlineEditing<MyModel> editing = new GridInlineEditing<MyModel>(mygrid){
        @SuppressWarnings("unchecked")
    @Override public <O> Field<O> getEditor(ColumnConfig<MyModel, ?> columnConfig) {
        if(valueColumnName.equals(columnConfig.getHeader().asString())) {
                MyModel myModel = tree.getSelectionModel().getSelectedItem();
            if(MyModelType.STRING.equals(myModel.getMyModelType())) {
                TextField textField =  new TextField();
                textField.setAllowBlank(Boolean.FALSE);
                return (Field<O>) textField;
            }
            else {
                TextArea textField =  new TextArea();
                textField.setAllowBlank(Boolean.FALSE);
                return (Field<O>) textField;
            }
        }
        return super.getEditor(columnConfig);
    }
};
editing.setClicksToEdit(ClicksToEdit.TWO);

PS: 这类似于下面的问题;但答案仅针对发布GXT 3.0.我是stackoverflow的新手,似乎建议您创建一个新问题,而不是在旧线程中添加新帖子. GXT EditorGrid:在一个单元一个单元地

PS: This is similar to question below; but answer is specific to post GXT 3.0. I am new to stackoverflow and it seems recommendation was to create new question instead of adding new post to old thread. GXT EditorGrid: choose cell editor type on a cell by cell basis

推荐答案

整日游玩后;我的同事(Praveen),我知道了.因此,不要尝试覆盖GridInlineEditing的getEditor()方法,而要覆盖startEditing()方法.另外,如果您有日期,列表等数据,则需要转换器.希望这对别人有帮助.

After playing around all day; my colleague(Praveen) and I figured it out. So instead of trying to override GridInlineEditing's getEditor() method override startEditing() method. Also, you will need converters if you have data like Date, List etc. Below is sample code; hope this help others.

final GridInlineEditing<MyModel> editing = new GridInlineEditing<MyModel>(tree){
            @Override public void startEditing(GridCell cell) {
                MyModel myModel= tree.getSelectionModel().getSelectedItem();
                if(MyModelType.TEXT.equals(myModel.getContextVariableType())) {
                    TextArea textField =  new TextArea();
                    textField.setAllowBlank(Boolean.FALSE);
                    super.addEditor(valueColumn, textField);
                }
                else if(MyModelType.BOOLEAN.equals(myModel.getContextVariableType())) {
                    SimpleComboBox<String> simpleComboBox = new SimpleComboBox<String>(new StringLabelProvider<String>());
                    simpleComboBox.setTriggerAction(TriggerAction.ALL);
                    simpleComboBox.add("YES");
                    simpleComboBox.add("NO");
                    super.addEditor(valueColumn, simpleComboBox);
                }
                else if(MyModel.INTEGER.equals(myModel.getContextVariableType())) {
                    SpinnerField<Integer> spinnerField = new SpinnerField<Integer>(new IntegerPropertyEditor());
                    spinnerField.setIncrement(1);
                    Converter<String, Integer> converter = new Converter<String, Integer>(){
                        @Override public String convertFieldValue(Integer object) {
                            String value = "";
                            if(object != null) {
                                value = object.toString();
                            }
                            return value;
                        }
                        @Override public Integer convertModelValue(String object) {
                            Integer value = 0;
                            if(object != null && object.trim().length() > 0) {
                                value = Integer.parseInt(object);
                            }
                            return value;
                        }
                    };
                    super.addEditor(valueColumn, converter, (Field)spinnerField);
                }
                else {
                    TextField textField =  new TextField();
                    textField.setAllowBlank(Boolean.FALSE);
                    super.addEditor(valueColumn, textField);
                }
                super.startEditing(cell);
            }
        };
        editing.setClicksToEdit(ClicksToEdit.TWO);

这篇关于GXT 3.x EditorGrid:在每个单元格的基础上选择单元格编辑器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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