In one of my projects, I had to do the same. I would recommend using CellClickHandler instead of trying to click on the anchor.
First, create a more convenient handler for your click actions:
public interface CellClickAction<P> { void onCellClick(P proxy); }
Use this plugin that contains a mapping for each ValueProvider in the grid:
public class GridCellClickPlugin<P> implements ComponentPlugin<Grid<P>> { private final Map<ValueProvider<P, ?>, CellClickAction<P>> mapping; public GridCellClickPlugin() { this.mapping = new HashMap<ValueProvider<P, ?>, CellClickAction<P>>(); } @Override public void initPlugin(final Grid<P> component) { component.addCellClickHandler(new CellClickHandler() { @Override public void onCellClick(CellClickEvent event) { if (!mapping.isEmpty()) { final ColumnConfig<P, ?> columnConfig = component.getColumnModel().getColumn(event.getCellIndex()); final CellClickAction<P> action = mapping.get(columnConfig.getValueProvider()); if (action != null) { final P proxy = component.getStore().get(event.getRowIndex()); action.onCellClick(proxy); } } } }); } }
Register a click handler for this column and enable the plugin:
final GridCellClickPlugin<LinkData> plugin = new GridCellClickPlugin<LinkData>(); plugin.getMapping().put(lp.url(), new CellClickAction<LinkData>() { @Override public void onCellClick(LinkData proxy) {
Change the text as a link:
linkConf = new ColumnConfig<LinkData, String>(lp.url(), 200, "URL"); linkConf.setCell(new AbstractCell<LinkData>() { @Override public void render(com.google.gwt.cell.client.Cell.Context context, LinkData value, SafeHtmlBuilder sb) { final Anchor anchor = new Anchor(value.getSomeText()); sb.appendHtmlConstant(anchor.getElement().toString()); } });
source share