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));
}}
因此,对于您的情况,只需将 getDeleteColumnIndex() 替换为 getCheckoxColumnIndex() 并返回您的列索引(如果它更改),并处理空格键而不是单击