将 clickHandler 添加到 GWT 中 CellTable 的行?
我创建了一个基本的 CellTable 并填充了一些数据。现在我想向每一行添加一个 clickHandler 但我不知道如何执行此操作。我已经为整个表创建了一个 clickEvent,但我想要为每一行创建一个 clickEvent。
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 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CellTable 内置了对处理单击事件的支持。您可以添加一个
CellPreviewHandler
,当单击一行时将调用该单元。它将接收事件中的许多项目,例如本机事件、单元格和数据行值。因为它不仅会触发单击事件,所以您需要检查单击事件是否被触发。只需测试传递的事件:boolean isClick = "click".equals(event.getNativeEvent().getType())。另一种选择是扩展受保护的方法
doSelection
,但它已被弃用,并且您需要确保设置了正确的KeyboardSelectionPolicy
以确保在单击时调用它完毕。请参阅接口KeyboardSelectionPolicy
的 JavaDoc 中的后者。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 rightKeyboardSelectionPolicy
set to make sure it's called when a click is done. See for the latter in the JavaDoc of the interfaceKeyboardSelectionPolicy
.选择单元格的另一种方法可以使用 NoSelectionModel 并将其添加到表中:
Another way to have a cell selected can be made using a NoSelectionModel and add it to the table: