Adding anchor to cellTable Column

3.2k views Asked by At

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

thanks.

3

There are 3 answers

0
Italo Borssatto On

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", "");
    }
};
0
Bikas Katwal On

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

1
yovetichg On

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