简体   繁体   English

网格中的GXT复选框

[英]GXT checkbox in grid

I need to update the store when the checkbox in the grid cell changed its state: to add or to remove the value from store. 当网格单元格中的复选框改变其状态时,我需要更新商店:添加或从商店中删除值。 how to handle this event? 如何处理这个事件? BTW, I create the checkbox in grid in this way: 顺便说一句,我用这种方式在网格中创建了一个复选框:

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

UPD2: Now I do the following: create checkboxes as firstly decided: 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);

than handle events in the grid like this: UPD3: 比如下处理网格中的事件: 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);
            }
        });

this is the right way. 这是正确的方法。

According to the docs found here , you can add a listener to the CellEditor 's Complete event. 根据此处找到的文档,您可以向CellEditorComplete事件添加侦听器。 In the Complete event Listener , perform whatever activity you need to accomplish. Complete事件Listener ,执行您需要完成的任何活动。

Update : Try the following 更新 :尝试以下操作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM