Question

I am working in a CustomDataGrid in GWT . What I want is to make a clickable column , using TableCellBuilder.I made an anchor element and added a click handler in it . Below is my code

       /**
         * 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();

        }
    }

However when I click on the anchor element , the click event is not being handled (As in the alert does not come). What am I missing here ?

Was it helpful?

Solution

When you append a Widget's toString to the document, you don't actually append the Widget itself, only its String representation. That's why you can't add a working handler to it.

To make it work inside the DataGrid, use a ClickableTextCell or a native method (JSNI).

You can see a clickable cell example at GWT Showcase as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top