How do I add a click handler to the GWT ButtonCell?
Asked Answered
T

2

17

I created a ButtonCell and a Column for it:

ButtonCell previewButton = new ButtonCell();
Column<Auction,String> preview = new Column<Auction,String>(previewButton) {
  public String getValue(Auction object) {
    return "Preview";
  }
};

How do I now add a click handler (e.g. ClickHandler) for this ButtonCell?

Thaumaturgy answered 29/12, 2010 at 17:35 Comment(0)
I
17

The Cell Sampler example includes use of clickable ButtonCells. Clicks on ButtonCells are handled by setting the FieldUpdater for the Column:

preview.setFieldUpdater(new FieldUpdater<Auction, String>() {
  @Override
  public void update(int index, Auction object, String value) {
    // The user clicked on the button for the passed auction.
  }
});
Indulgent answered 29/12, 2010 at 20:41 Comment(2)
but how to place regular button in cell table??Thaumaturgy
redrawButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { contactList.redraw(); } });Quintero
A
0
 //Prevent mouse events  for table cell
 CellPreviewEvent.Handler<Auction > manager = DefaultSelectionEventManager.createBlacklistManager(4);//column number
 cellTable.setSelectionModel(selectionModel, manager);

 new Column<Auction , String>(new ButtonCell()){

    @Override
    public String getValue(Auction object) {
        return "Preview";
    }

    @Override
    public void onBrowserEvent(Cell.Context context, Element elem, Auction object, NativeEvent event) {
        event.preventDefault();

       //TODO implement event handling 
    }
}
Angelinaangeline answered 11/7, 2013 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.