1

Is there a way to add a clickHandler to a Column in a cellTable in GWT ??

I do not see any option from the documentation for TextColumn.

My requirement goes this way - I have to display 5 columns of data in a cell table and one of the columns must have a onClick event to be fired. But I found no way to add a clickhandler to the textColumn.

if this was supposed to be done in regular html it would not take me 5 seconds to write the code -

BenMorel
  • 34,448
  • 50
  • 182
  • 322
ravi
  • 1,707
  • 4
  • 29
  • 44
  • 1
    I've answered your other question. Use a `ClickableTextCell`. A good way to find out of all the cells you can use is to go to the Cell interface and press F4 on it in Eclipse to see the class hierarchy. There are many cells already provided to you, and if none of them suit your needs, you can always write your own. – Strelok Oct 24 '11 at 06:07

1 Answers1

0

Write your custom cell (here an example I wrote based on GWT ActionCell) :

public abstract class ActionTextCell<C> extends AbstractCell<C> {

  public static interface Delegate<T> {
    void execute(T object);
  }

  private final Delegate<C> delegate;

  public ActionTextCell(Delegate<C> delegate) {
    super("click", "keydown");
    this.delegate = delegate;
  }

  @Override
  protected void onEnterKeyDown(Context context, Element parent, C value, NativeEvent event,
      ValueUpdater<C> valueUpdater) {
    delegate.execute(value);
  }

  @Override
  public void onBrowserEvent(Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    if ("click".equals(event.getType())) {
      onEnterKeyDown(context, parent, value, event, valueUpdater);
    }
  }

  @Override
  public void render(Context context, C value, SafeHtmlBuilder sb) {
    sb.append(new SafeHtmlBuilder().appendHtmlConstant("<span>" + render(value) + "</span>")
      .toSafeHtml());
  }

  public abstract String render(C value);

}

And use it within an IndentityColumn which you add to your CellTable:

final ActionTextCell<MyClass> cell = new ActionTextCell<MyClass>(new ActionTextCell.Delegate<MyClass>() {

      @Override
      public void execute(MyClass c) {
        // do something with c
      }
    }) {

      @Override
      public String render(MyClass c) {
        // return a string representation of c
      }
    };

final IdentityColumn<MyClass> column = new IdentityColumn<MyClass>(cell);
Tom Miette
  • 129
  • 3