2

我有表格,我想从双击的行中接收数据。我该怎么做?但我不能使用 addCellPrevieHandler,因为双击事件在那里不起作用。

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());
4

1 回答 1

2

您可以使用选择模型:

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());
于 2013-09-02T16:03:41.960 回答