1

i am trying to add anchor to cell Table column is there a way to do this ????

thanks.

ahmed Shoeib
  • 254
  • 6
  • 22

3 Answers3

0

This question is quite old but still adding the answer as might help others. In below code I am using clickableTextCell and some styling change to give a feel of Anchor ;)

Column<YourDataClass, String> columnValue = new Column<YourDataClass, String>(
    new ClickableTextCell()) {

  @Override
  public String getCellStyleNames(Cell.Context context, YourDataClass  object) {
    return style.clickableText();
  }


  @Override
  public String getValue(YourDataClass object) {       

    return "Anchor Name"; //This is anchor text eg: Download Something
  }
};

columnValue.setFieldUpdater(new FieldUpdater<YourDataClass, String>() {
  @Override
  public void update(int index, YourDataClass obj, String value) {
    //Do stuff for click event.
  }
});

agentsTable.addColumn(columnValue, " ");
agentsTable.setColumnWidth(columnValue, 10,com.google.gwt.dom.client.Style.Unit.PCT);

add below code in your class for styling;

@UiField
Style style;
public interface Style extends CssResource {
  String clickableText();
}

Add below style to your ui.xml file:

.clickableText{
    align: left;
    color: blue;
    text-decoration: underline;
    }

Read http://www.pandurangpatil.com/2014/03/gwt-access-style-defined-inside-uixml.html to know how to access styling from ui.xml in your class

Bikas Katwal
  • 1,895
  • 1
  • 21
  • 42
0

try using ClickableTextCell and setting its ValueUpdater to call whatever method you would need the anchor to do

yovetichg
  • 1
  • 3
0

Create a Column overriding the onBrowserEvent method.

Like this:

new Column<T, String>(new TextCell()) {
    @Override
    public String getValue(T object) {
        return object.getProperty();
    }

    @Override
    public void onBrowserEvent(Context context, Element elem, T object, NativeEvent event) {
        // TODO You can check which event you want to catch
        Window.open("http://www.stackoverflow.com", "StackOverFlow", "");
    }
};
Italo Borssatto
  • 15,044
  • 7
  • 62
  • 88