2014-01-31 50 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處看到可點擊的單元示例。

相關問題