Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have created a basic CellTable and filled it with some data. Now I want to add a clickHandler to each row but I'm not sure how to do this. I've created a clickEvent for the whole table but I want one for each row.

    table.sinkEvents(Event.ONCLICK);
    table.setTitle("Click me");
    table.setSize("600px", "600px");
    table.addDomHandler(new ClickHandler()
    {
        @Override
        public void onClick(ClickEvent event)
        {
            Window.alert("You clicked!" +);

        }
    }, ClickEvent.getType());

Can I do something similar to add clickEvent for each row?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
438 views
Welcome To Ask or Share your Answers For Others

1 Answer

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()).

Another option is to extend the protected method doSelection, but it's deprecated and in you need to als make sure you have the right KeyboardSelectionPolicy set to make sure it's called when a click is done. See for the latter in the JavaDoc of the interface KeyboardSelectionPolicy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...