【问题标题】:GXT checkbox in grid网格中的 GXT 复选框
【发布时间】:2013-06-23 23:44:50
【问题描述】:

当网格单元格中的复选框更改其状态时,我需要更新存储:添加或删除存储中的值。如何处理这个事件? 顺便说一句,我以这种方式在网格中创建复选框:

column = new ColumnConfig();
column.setId("accepted");
column.setHeader("Accepted");
column.setWidth(55);

UPD2: 现在我执行以下操作: 按照最初的决定创建复选框:

CheckColumnConfig checkColumn = new CheckColumnConfig("accepted", "", 55);
CellEditor checkBoxEditor = new CellEditor(new CheckBox());        
checkBoxEditor.setToolTip("If you click here server will consider this rule checking your messages");
checkColumn.setEditor(checkBoxEditor);
checkColumn.setHeader("apply");
configs.add(checkColumn);

比像这样处理网格中的事件: UPD3:

grid.addListener(Events.CellMouseUp, new Listener<GridEvent>() {
            @Override
            public void handleEvent(GridEvent be) {
                PropertyItem item;
                    if (grid.getStore().getAt(be.getRowIndex()).isAccepted()){
                        item = new PropertyItem(val1, val2, val3, true);
                    } else {
                        item = new PropertyItem(val1, val2, val3, false);
                    }
                    store.update(item);
                    store.commitChanges();
                    saveProperties(store, customerId, toRemove);
            }
        });

这是正确的方法。

【问题讨论】:

    标签: java checkbox gxt


    【解决方案1】:

    根据找到的文档here,您可以为CellEditorComplete 事件添加一个监听器。在Complete 事件Listener 中,执行您需要完成的任何活动。

    更新: 试试下面的

    column.setRenderer(new GridCellRenderer() {
    
        @Override
        public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, final ListStore store, Grid grid) {
            CheckBox box = new CheckBox();
            box.addListener(Events.Change, new Listener<FieldEvent>() {
                 @Override
                 public void handleEvent(FieldEvent be) {
                     st.commitChanges();
                     saveProperties(st, customerId, toRemove);
    
                    // I'm not sure what saveProperties is, but see if this works now.
                    // this event should DEFINITELY be fired when the checkbox is clicked
                    // so if it doesn't work, try changing how you do your code here
                    // maybe by doing model.set(property, (Boolean) be.getValue()); or something
                 }
            });
            return box;
        }
    });
    

    【讨论】:

    • 确保在render 方法中创建CheckBox 的本地实例,例如CheckBox box = new CheckBox();。我还编辑了我的答案,以向您展示我认为您应该使用的听众。
    • 但 Listener() 不能与方法 handleEvent (FieldEvent be) 一起使用。 checkchangedEvent 和 FieldEvent 不一致
    • 糟糕,应该将 作为 Listener 泛型类型。我已酌情更新
    • 这是一个选择合适事件的问题。但现在我有另一个问题:此更改不会更新存储中的值(您知道,您需要一个 ListStore 来构建网格)并且没有正确显示它。以前,当我更改任何单元格时,商店中的对应值发生了变化。还是我现在必须自己更改?
    • 尝试在model.set(property, (Boolean) be.getValue()); 之后添加对store.update(model); 的调用,以告知商店模型已更新。
    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2012-05-18
    • 2013-07-31
    • 2017-03-24
    相关资源
    最近更新 更多