Question

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");        
    }
  }
});
Était-ce utile?

La solution

DataGrid has many things in common with CellTable. So solutions from this question must work for you too:

  • Using CellPreviewHandler count time between two clicks
  • Or you can add DoubleClickHandler using addDomHandler method

Autres conseils

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());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top