开发者

How to add a Clickhandler to a cellTable cell (or row )

I would like to have a handler on a column of my cellTable.The column is an ImageResourceCell and I would that when I click on it, it delete the row Here is my code

Column<MyObject, ImageResource> imageColumn = 
    new Column<MyObject, ImageResource>(newImageResourceCell()) {
        @Override
  开发者_开发知识库      public ImageResource  getValue(MyObject object) {
             return Bundle.Util.getInstance().deleteRegexButton();
        }
    }; 
cellTable.addColumn(imageColumn,SafeHtmlUtils.fromSafeConstant("<br/>");

But I didn't know how to insert a handler as described Is it possible ??

any suggestions are welcome

Thanks.


Cells have to declare the events they handle, then the browser event can be passed to the cell.

    ImageResourceCell myImgCell = new ImageResourceCell() {
        public Set<String> getConsumedEvents() {
            HashSet<String> events = new HashSet<String>();
            events.add("click");
            return events;
        }
    };

    Column<MyObject, ImageResource> imageColumn = new Column<MyObject, ImageResource>(myImgCell) {
        @Override
        public ImageResource getValue(MyObject dataObj) {
                    return Bundle.Util.getInstance().deleteRegexButton();
        }

        @Override
        public void onBrowserEvent(Context context, Element elem,
                MyObject object, NativeEvent event) {
            super.onBrowserEvent(context, elem, object, event); 
            if ("click".equals(event.getType())) {
                //call your click event handler here
            }
        }
    };

More info here: http://code.google.com/webtoolkit/doc/latest/DevGuideUiCustomCells.html

Note: this works with GWT 2.4, did not try with GWT 2.2.


Have you seen Adding clickHandler to row in CellTable in GWT??


A CellTable has built in support for handling click events. You can add a CellPreviewHandler that will be called among others when a row is clicked. It will receive a number of items in the event like the native event, cell, and data row value. Because it fires not only for click events you need to check if the click event was fired. Simply test the event passed:

boolean isClick = "click".equals(event.getNativeEvent().getType())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜