【问题标题】:How to add clickhandler to the subrow of the celltablebuilder如何将点击处理程序添加到单元格表格构建器的子行
【发布时间】:2012-09-26 06:40:28
【问题描述】:

我可以使用 celltablebuilder 构建自定义行。单击特定的锚单元格时,我可以为该行构建额外的子行。这个子行有按钮,当点击按钮时我做了一些动作。我可以在子行中添加带有 clickhandler 的按钮,但是当单击按钮时没有发生任何事情,clickhandler 没有触发。

有人可以帮忙吗。

protected void buildRowImpl(GridDTO rowValue, int absRowIndex ) {
  buildRows(rowValue, absRowIndex, true);
  if (showingFriends.contains(rowValue.getComponentId())) {
     buildAdditonalRows( absRowIndex, gridDTO);
  }

}
private void buildAdditonalRows(int index, GridDTO rowValue, ){ 
     TableRowBuilder row = startRow();
     td = row.startTD();
     if(rowValue.getXpath() != null){
    //td.text(rowValue.getXpath());
    renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
 }else{
    td.text("");
 }
     td.endTD();
     td = row.startTD();
     Button button = new Button ();
 button.setText("Save");
 button.addClickHandler(new ClickHandler() {
 @Override
 public void onClick(ClickEvent event) {
     Window.alert("ssss");
     }
 });
 DivBuilder div = td.startDiv();
 div.html(new afeHtmlBuilder().appendHtmlConstant(button.toString()).toSafeHtml());
 div.end();
     td.endTD();
     row.endTR();
}

【问题讨论】:

标签: gwt-celltable gwt-2.5


【解决方案1】:

CellPreviewEvent 提供子索引。您可以使用它来获取子行值。 用法示例:

dataGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TreeItem>() {
    @Override
    public void onCellPreview(final CellPreviewEvent<TreeItem> event) {
        if(event.getNativeEvent().getType().equals(BrowserEvents.CLICK)){
             if(event.getContext().getSubIndex()>0){
                    event.getValue().getChild(event.getContext().getSubIndex()-1);
             }
        }
    }
});

或者您可以提供带有 selectionMode 的自定义 CellPreviewEvent.Handler 实现。更多详情可以关注AbstractHasData

【讨论】:

    【解决方案2】:

    我有类似的情况,我需要一个单元格内的小部件来监听点击事件......我发现一旦你将小部件插入到单元格中,它就不会响应事件(换句话说,只有构成小部件的实际 HTML 被放入单元格中,不包括任何类型的事件处理)。解决方法是将事件添加到单元格(您可以为该特定单元格小部件创建自定义单元格类并覆盖 OnBrowserEvent 以侦听事件。)

    请参阅GWT: On adding custom widget to celltable losing events of the custom widgets 以获得更有说服力的解释和示例代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多