如何将单击处理程序添加到 GWT ButtonCell?

2022-09-03 07:01:35

我为它创建了一个 ButtonCell 和一个 Column

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

我现在如何为此 ButtonCell 添加单击处理程序(例如 ClickHandler)?


答案 1

单元格采样器示例包括使用可单击的按钮单元格。对 ButtonCell 的单击通过设置列的字段更新程序来处理:

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.
  }
});

答案 2
 //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 
    }
}

推荐