我正在使用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;
}
});
感谢。
答案 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;
}
});
我希望这会有所帮助