1

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

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);
            }
        });

这是正确的方法。

4

1 回答 1

2

根据此处找到的文档,您可以向CellEditor'sComplete事件添加侦听器。在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;
    }
});
于 2013-06-19T14:32:54.283 回答