我为DataGrid添加了双击事件,但它无法正常工作。代码处理单击,但不处理双击。
请帮忙。
private DataGrid<Contract> table = new DataGrid<Contract>();
table.addCellPreviewHandler(new Handler<Contract>() {
@Override
public void onCellPreview(final CellPreviewEvent<Contract> event) {
if (BrowserEvents.DBLCLICK.equals(event.getNativeEvent().getType())) {
//it doesn't handle
Window.alert("Tro-lo-lo");
}
if (BrowserEvents.CLICK.equals(event.getNativeEvent().getType())) {
//it handles
Window.alert("Tru-la-la");
}
}
});
答案 0 :(得分:1)
DataGrid与CellTable有许多共同之处。因此this question的解决方案也必须适合您:
CellPreviewHandler
次数DoubleClickHandler
方法addDomHandler
答案 1 :(得分:1)
dataGrid.addDomHandler(new DoubleClickHandler() {
@SuppressWarnings("unchecked")
@Override
public void onDoubleClick(DoubleClickEvent event) {
DataGrid<YourDataProviderType> grid = (DataGrid<YourDataProviderType>) event.getSource();
int row = grid.getKeyboardSelectedRow();
YourDataProviderType item = grid.getVisibleItem(row);
Window.alert("Do Something Here");
}
}, DoubleClickEvent.getType());