将 clickHandler 添加到 GWT 中 CellTable 中的行? [英] Adding clickHandler to row in CellTable in GWT?

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

问题描述

我创建了一个基本的 CellTable 并用一些数据填充它.现在我想为每一行添加一个 clickHandler 但我不知道如何做到这一点.我已经为整个表格创建了一个 clickEvent,但我希望每一行都有一个.

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

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

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

推荐答案

CellTable 内置了对处理单击事件的支持.您可以添加一个 CellPreviewHandler,当单击一行时将调用它.它将接收事件中的许多项目,如本机事件、单元格和数据行值.因为它不仅针对点击事件触发,所以您需要检查点击事件是否被触发.只需测试通过的事件:boolean isClick = "click".equals(event.getNativeEvent().getType()).

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

另一种选择是扩展受保护的方法 doSelection,但它已被弃用,您还需要确保设置了正确的 KeyboardSelectionPolicy 以确保在调用时调用它单击完成.后者见接口KeyboardSelectionPolicy的JavaDoc.

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.

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

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