使用时 TableBuilder
要创建行和子行,选择模型未按预期工作。
当单击子行的复选框时,该行未被选中,但是,父行被选中。
我试图重载 onBrowserEvent
的 CheckboxCell
为了手动处理选择,但似乎 DataGrid 本身在按下复选框单元时会触发选择事件。
如果行和子行来自同一类型,如何添加支持行和子行的选择模型?
最佳答案
@Override
public void onBrowserEvent(Context context, Element elem, final T object,
NativeEvent event) {
// The provided row is always the root row, so we need to find the
// correct one when a sub row was edited
actualIndex = context.getSubIndex();
actualObject = object;
if (0 != context.getSubIndex() && object instanceof RowDTO) {
actualIndex = context.getSubIndex();
actualObject = (T) ((RowDTO) object).getChild(actualIndex - 1);
context = new Context(context.getIndex(), context.getColumn(),
actualObject, actualIndex);
}
ValueUpdater<C> valueUpdater = (getFieldUpdater() == null) ? null
: new ValueUpdater<C>() {
@Override
public void update(C value) {
getFieldUpdater().update(actualIndex, object, value);
}
};
getCell().onBrowserEvent(context, elem, getValue(actualObject), event,
valueUpdater);
}
关于带有子行的 GWT 2.5 DataGrid SelectionModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11744198/