GXT checkbox in grid

女生的网名这么多〃 提交于 2019-12-24 06:59:28

问题


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:

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:

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.


回答1:


According to the docs found here, you can add a listener to the CellEditor's Complete event. In the Complete event Listener, perform whatever activity you need to accomplish.

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


来源:https://stackoverflow.com/questions/17169052/gxt-checkbox-in-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!