网格中的GXT复选框 [英] GXT checkbox in grid

查看:143
本文介绍了网格中的GXT复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:现在我执行以下操作:
创建复选框作为首先决定:

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

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

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

这是正确的方法。

推荐答案

根据找到的文档这里,您可以添加一个监听器到 CellEditor 完成事件。在完成事件侦听器中,执行您需要完成的任何活动。

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

这篇关于网格中的GXT复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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