Saturday, January 28, 2012

Re: How to add a link (anchor) to a CellTable?

You will use the Column class directly and tell it to use your custom cell:

Column col = new Column<Entry, String>(new YourCustomCell()) {
   @Override
   public String getValue(Entry obj)
   {
    return (obj.myAttribute);
   }
}

How to implement a custom cell can be found in the documentation.


If you only need a simple link you could also just use the SafeHtmlCell:

public interface SimpleCellTemplates extends SafeHtmlTemplates {   @Template("<a href=\"{0}\">{1}</a>")   SafeHtml anchor(SafeUri href, String name); }

static final SimpleCellTemplates cell = GWT.create(SimpleCellTemplates.class)

Column col = new Column<Entry, SafeHtml>(new SafeHtmlCell()) {
   @Override
   public SafeHtml getValue(Entry obj)
   {
    SafeUri href = //construct your href as SafeUri using UriUtils
    return cell.anchor(href, obj.getName());
   }
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/c5cjJwKQpC8J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment