在GWT中的CellTable中添加clickHandler? [英] Adding clickHandler to row in CellTable in GWT?

查看:89
本文介绍了在GWT中的CellTable中添加clickHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基本的CellTable并填充了一些数据。现在我想添加一个clickHandler到每一行,但我不知道如何做到这一点。我为整个表创建了一个clickEvent,但每行都需要一个。
$ b

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

我可以做类似的事情为每行添加clickEvent吗?

解决方案

CellTable内建支持处理点击事件。你可以添加一个 CellPreviewHandler ,当单击一行时将被调用。它将在事件中接收许多项目,如本地事件,单元格和数据行值。因为它不仅触发点击事件,还需要检查点击事件是否被触发。只需测试传递的事件: boolean isClick =click.equals(event.getNativeEvent()。getType())


$ b $另一个选择是扩展受保护的方法 doSelection ,但它已被弃用,并且您需要确保您拥有正确的 KeyboardSelectionPolicy 设置为确保点击完成后调用它。请参阅接口 KeyboardSelectionPolicy 的JavaDoc中的后者。


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?

解决方案

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.

这篇关于在GWT中的CellTable中添加clickHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆