2014-01-31 47 views
0

我正在GWT中的CustomDataGrid中工作。我想要做一个可点击的列,使用TableCellBuilder.I做了一个锚点元素并在其中添加了一个点击处理程序。下面是我的代码如何将点击处理程序添加到在GWT中的Tablecell中添加的锚点元素?

 /** 
     * Builds cells of the details shown when main service category is clicked 
     * 
     * @author smrita 
     * @param rowValue 
     *   : A <link> String </link> which is the value of each cell 
     * @param cellStyles 
     *   : A<link>String</link> which is the style of each cell. 
     */ 
     public void buildEachServiceCommissionCell(String rowValue, String cellStyles) { 
        TableRowBuilder detailCell = startRow(); 

      TableCellBuilder td = detailCell.startTD(); 

      cellStyles = cellStyles + " " + resources.esewaCss().commissionListDataGridChildRows(); 
      td.className(cellStyles); 
      td.style().outlineStyle(OutlineStyle.NONE).endStyle(); 

      Anchor removeAnchor = new Anchor(rowValue); 
      removeAnchor.addClickHandler(new ClickHandler() { 

       @Override 
       public void onClick(ClickEvent arg0) { 
        Window.alert("clicked"); 
       } 

      }); 

      td.html(new SafeHtmlBuilder().appendHtmlConstant(removeAnchor.toString()).toSafeHtml()); 
      detailCell.endTD(); 

     } 
    } 

但是,当我点击锚元素,点击事件没有被处理(因为警报没有来)。我在这里错过了什么?

回答

0

当您将Widget的toString附加到文档中时,您实际上并不追加Widget本身,仅附加其字符串表示。这就是为什么你不能添加工作处理程序。

要使其在DataGrid内部工作,请使用ClickableTextCell或本机方法(JSNI)。

您也可以在GWT Showcase处看到可点击的单元示例。

相关问题