如何获取网格GXT上所选复选框的行索引

时间:2013-06-26 10:21:39

标签: checkbox grid onchange gxt

我正在使用GXT(2.2.5)并且需要在网格上获取chenged复选框的行索引。我正在做的是创建一个网格并应用GridCellRender在第一列显示一个复选框,然后当任何checkBox更改其值(OnChange事件的监听器)时,必须采用更改复选框的行索引。到目前为止,这是我的代码的一部分:

    checkColumn.setRenderer(new GridCellRenderer() {
        @Override
        public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid gri) {
            final CheckBox check = new CheckBox();
            check.addListener(Events.OnChange, new Listener<BaseEvent>() {
                @Override
                public void handleEvent(BaseEvent be) {
                    //Here we get the row index
                }
            });
            return check;
        }
    });

感谢。

1 个答案:

答案 0 :(得分:0)

你可以这样:

 checkColumn.setRenderer(new GridCellRenderer() {
        @Override
        public Object render(final ModelData model, String property, ColumnData config, int rowIndex, int colIndex, final ListStore store, Grid gri) {
            final CheckBox check = new CheckBox();
            check.addListener(Events.OnChange, new Listener<BaseEvent>() {
                @Override
                public void handleEvent(BaseEvent be) {
                    //////////
                    int indx = store.indexOf(model);
                    //////////

                }
            });
            return check;
        }
    });

(请注意,您必须转换为最终的商店模型变量)

或许这个:

checkColumn.setRenderer(new GridCellRenderer() {
        @Override
        public Object render(final ModelData model, String property, ColumnData config, int rowIndex, int colIndex, final ListStore store, Grid gri) {

            final CheckBox check = new CheckBox();
            check.setData("indx", store.indexOf(model));

            check.addListener(Events.OnChange, new Listener<BaseEvent>() {
                @Override
                public void handleEvent(BaseEvent be) {
                    //////////
                    int indx = ((CheckBox) be.getSource()).getData("indx");
                    //////////

                }
            });
            return check;
        }
    });

我希望这会有所帮助