celltable
当我像这样使用时,
dgrid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
编辑字段空间单击选择行,所以我像这样使用
dgrid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
但是在这一行中,只需单击一下即可选择..
我只想checkbox
进行选择,列点击不应该选择行,任何人都可以帮我实现这个目标吗?
答案 0 :(得分:0)
protected DefaultSelectionEventManager.EventTranslator<ProductProxy> eventTranslator = new DefaultSelectionEventManager.EventTranslator<ProductProxy>() {
@Override
public boolean clearCurrentSelection(CellPreviewEvent<ProductProxy> event) {
NativeEvent nativeEvent = event.getNativeEvent();
String type = nativeEvent.getType();
if (BrowserEvents.CLICK.equals(type)) {
int index = event.getContext().getColumn();
if (index == getDeleteColumnIndex())
return true;
}
return false;
}
@Override
public SelectAction translateSelectionEvent(CellPreviewEvent<ProductProxy> event) {
NativeEvent nativeEvent = event.getNativeEvent();
String type = nativeEvent.getType();
if (BrowserEvents.CLICK.equals(type)) {
if (event.getColumn() == getDeleteColumnIndex()) {
ProductTable.this.productTableManager.deleteProduct(event.getValue());
return SelectAction.IGNORE;
}
}
return SelectAction.DEFAULT;
}
};
然后在CellTable中使用该选择器:
我有
class MyTable extends CellTable {
void myInit() {
setSelectionModel(selectionModel, DefaultSelectionEventManager.createCustomManager(eventTranslator));
}}
因此,对于您的情况,只需用getCheckoxColumnIndex()替换getDeleteColumnIndex()并返回列索引(如果它更改),并处理空格键而不是单击