在表单元格中创建链接,然后单击以打开浮动弹出窗口 [英] create link in table cell and open float popup by click from it
问题描述
我有一个CellTable,需要一列在单元格内包含超链接和onclick处理程序的列. 第一个问题,如果我有错,怎么办?
I have a CellTable and need a column with hyper links and onclick handlers inside cells. 1st question, what am doing wrong if I have:
Column<MyObject, Anchor> linkColumn = new Column<MyObject, Anchor>(
new AnchorCell()) {
@Override
public Anchor getValue(final obj) {
Anchor link = new Anchor("link");
link.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("clicked ");
}
});
return link;
}
};
cellTable.addColumn(linkColumn, "link column");
...
public class AnchorCell extends AbstractCell<Anchor> {
@Override
public void render(Context context, Anchor h, SafeHtmlBuilder sb) {
sb.append(SafeHtmlUtils.fromTrustedString(h.toString()));
}
}
-但是单击链接-没有任何反应
-but clicking to link - happens nothing
和第二个问题:用该ClickHandler的文本内容打开浮动控件(基于div左右,而不是分开的浏览器窗口)的更好的方法是什么?
and 2nd question: what's better way to open float (based on div or so, not separated browser window) pupup with text contents from that ClickHandler?
推荐答案
在CellTable中,您没有将Anchor小部件添加到表中.您只是添加了一些HTML.窗口小部件的功能均无法正常运行,因为窗口实际上不在表中.
In a CellTable, you aren't adding the Anchor widget to the table. You're just adding some HTML. None of the widget's functions will work as they normally would, because the widget is not actually in the table.
您可以重写onBrowserEvent以获取诸如单击单元格之类的事件.这些事件仍然会发生,因为它们是浏览器固有的,不需要传播小部件框架.我认为这是达到所需效果的最佳方法.
You can override onBrowserEvent to get events like clicking on the cells. These events still happen because they are native to the browser and don't need the widget framework to propagate. I think this is the best way to achieve the effect you want.
这篇关于在表单元格中创建链接,然后单击以打开浮动弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!