Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In one of my project I had to do the same. I'd recommend to use <code>CellClickHandler</code> instead of trying to catch click on the anchor.</p> <p>First create more convenient handler for your click actions:</p> <pre><code>public interface CellClickAction&lt;P&gt; { void onCellClick(P proxy); } </code></pre> <p>Use this plugin which holds mapping for every ValueProvider in the grid:</p> <pre><code>public class GridCellClickPlugin&lt;P&gt; implements ComponentPlugin&lt;Grid&lt;P&gt;&gt; { private final Map&lt;ValueProvider&lt;P, ?&gt;, CellClickAction&lt;P&gt;&gt; mapping; public GridCellClickPlugin() { this.mapping = new HashMap&lt;ValueProvider&lt;P, ?&gt;, CellClickAction&lt;P&gt;&gt;(); } @Override public void initPlugin(final Grid&lt;P&gt; component) { component.addCellClickHandler(new CellClickHandler() { @Override public void onCellClick(CellClickEvent event) { if (!mapping.isEmpty()) { final ColumnConfig&lt;P, ?&gt; columnConfig = component.getColumnModel().getColumn(event.getCellIndex()); final CellClickAction&lt;P&gt; action = mapping.get(columnConfig.getValueProvider()); if (action != null) { final P proxy = component.getStore().get(event.getRowIndex()); action.onCellClick(proxy); } } } }); } } </code></pre> <p>Register click handler for this column and init plugin:</p> <pre><code>final GridCellClickPlugin&lt;LinkData&gt; plugin = new GridCellClickPlugin&lt;LinkData&gt;(); plugin.getMapping().put(lp.url(), new CellClickAction&lt;LinkData&gt;() { @Override public void onCellClick(LinkData proxy) { //do the desired action here: redirect to some url, show pop-up window, etc } }); plugin.init(grid); </code></pre> <p>Render your text as a link:</p> <pre><code>linkConf = new ColumnConfig&lt;LinkData, String&gt;(lp.url(), 200, "URL"); linkConf.setCell(new AbstractCell&lt;LinkData&gt;() { @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()); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload