Reputation: 11201
Any idea how can I add anchor in my CellTable
? I found the same question here but couldn't get a working solution for that.
Could someone provide some working code for adding an anchor in a CellTable column?
Upvotes: 0
Views: 1805
Reputation: 5599
I like using SafeHtmlCell
to render Widget's HTML into CellTable
:
Column<MyTableType, SafeHtml> anchorColumn = new Column<MyTableType, SafeHtml>(new SafeHtmlCell()) {
@Override
public SafeHtml getValue(MyTableType object) {
Anchor anchor = new Anchor(...);
return SafeHtmlUtils.fromTrustedString(anchor.toString());
}
};
Note that Widget.toString();
returns Widget's HTML snippet meant to be viewed in the debugger. It will not contain any handlers nor listeners. It will be just HTML, but it is just enough to render simple things in the CellTable
.
Upvotes: 2
Reputation: 18331
The widget Anchor
cannot be added into a CellTable
, as all cell widgets only know how to draw Cell<C>
instances. This lets them draw and redraw their content much more quickly/efficiently than they could do with Widget
s.
A html anchor element, <a href='someUrl'>text</a>
can be drawn easily as a Cell
. Subclass AbstractCell
and define the render method to draw this html, interleaved with any text or link that you want to redirect to. Then, when building the CellTable
, pass this Cell
instance into the Column
constructor.
Take a look at some of the existing Cell
s in GWT to see how else you can draw things (like ButtonCell.render
makes a button instead of an a), or how to handle events (AnchorCell
on how to handle a click programmaticly instead of letting the a redirect to a new page, or TextInputCell
for a more complex example).
Upvotes: 3