Question

I have table and I want to receive data from double clicked rows. How can I do it? But I can't use addCellPrevieHandler, because double click event doesn't work there.

Datagrid<Contract> table = new Datagrid<Contract>();
table.addDomHandler(new DoubleClickHandler(){
  @Override
  public void onDoubleClick(final DoubleClickEvent event) {    
    //I want to receive data from row here    
  }
}, DoubleClickEvent.getType());
Was it helpful?

Solution

You can use a selection model:

Datagrid<Contract> table = new Datagrid<Contract>();
SingleSelectionModel<Contract> selectionModel = new SingleSelectionModel<Contract>();
table.setSelectionModel(selectionModel);
table.addDomHandler(new DoubleClickHandler() {
    @Override
    public void onDoubleClick(final DoubleClickEvent event) {
        Contract selected = selectionModel.getSelectedObject();
        if (selected != null) {
            // TODO
        }
    }
}, DoubleClickEvent.getType());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top