Reputation: 463
I added double click event for DataGrid, but it doesn't work correctly. The code handles a single click, but it does not handle double click.
Please help.
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");
}
}
});
Upvotes: 1
Views: 2915
Reputation: 11
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());
Upvotes: 1
Reputation: 7817
DataGrid has many things in common with CellTable. So solutions from this question must work for you too:
CellPreviewHandler
count time between two clicksDoubleClickHandler
using addDomHandler
methodUpvotes: 1