GWT:如何在旅途中添加/删除小区表中的按钮

时间:2012-02-04 01:21:55

标签: gwt

我的CellTable

中有这个按钮单元格
ButtonCell reListCell = new ButtonCell();
reListColumn = new Column<EmployerJobs, String>(reListCell) {
  @Override
  public String getValue(EmployerJobs object) {
    return "ReList";
  }
};

ctJobs.addColumn(reListColumn, 
    EmployerDashBoardConstants.EMPTYHEADERCOLUMN);

但我只希望在下面的条件通过

时出现这个单元格
public void getDateDiff(final EmployerJobs object) {
  rpcService.getDateDiff(object.getJobValidDate(), new AsyncCallback<Boolean>() {
    public void onFailure(Throwable caught) {
    }

    public void onSuccess(Boolean jobExpired) {
      if(jobExpired) {
        // HERE I WANT TO SHOW MY RELISTCELL, means if the job is expired only then 
        // there will be a button showing relist would be appear in that row ,for 
        // the jobs which are not expired NO button should appear..  
      }
    }
  });
}

我怎样才能实现这一目标?

感谢

3 个答案:

答案 0 :(得分:4)

我同意DTing 查询每个单元/行的后端并不是很有效。 我希望将信息( jobExpired )放入您的EmployerJobs课程,并在您请求EmployerJobs的{​​{1}}列表中转移信息时显示在CellTable
您可以定期更新列表以考虑更改(请参阅expenses示例了解如何执行此操作)。

但是你的初步问题(隐藏细胞)。有两种解决方案:

ActionCell:

ActionCell<EmployerJobs> reListCell = new ActionCell<EmployerJobs>("ReList",
    new ActionCell.Delegate<EmployerJobs>() {
        @Override
        public void execute(EmployerJobs object) {
           // code to be executed 
        }
     }) 
 {
     @Override
     public void render(Cell.Context context,EmployerJobs value,SafeHtmlBuilder sb) {
         if (value.isJobExpired())   // isJobExpired returns the field jobExpired.
             super.render(context,value,sb);
         }
 };

 reListColumn = new Column<EmployerJobs, EmployerJobs>(reListCell) {
      @Override
      public String getValue(EmployerJobs object) {
        return object;
      }
 };

 ctJobs.addColumn(reListColumn, 
    EmployerDashBoardConstants.EMPTYHEADERCOLUMN);
  • 使用ButtonCell并覆盖Column的render方法。

扣式:

ButtonCell reListCell = new ButtonCell();
reListColumn = new Column<EmployerJobs, String>(reListCell) {
  @Override
  public String getValue(EmployerJobs object) {
    return "ReList";
  }
  @Override
  public void render(Cell.Context context,EmployerJobs object,SafeHtmlBuilder sb) {
     if (value.isJobExpired())   // isJobExpired returns the field jobExpired.
        super.render(context,value,sb);
  }
};

ctJobs.addColumn(reListColumn, 
    EmployerDashBoardConstants.EMPTYHEADERCOLUMN);

答案 1 :(得分:1)

刚试过Umit解决方案#2 ButtonCell。它有效!

要将特定操作链接到按钮,请使用reListColumn.setFieldUpdater(new FieldUpdater .... 需要

答案 2 :(得分:1)

我也试过了ButtonCell解决方案。但是,如果您单击一个没有按钮的单元格,则会出现客户端错误:

  

com.google.gwt.core.client.JavaScriptException:(TypeError)@ com.google.gwt.core.client.impl.Impl :: apply(Ljava / lang / Object; Ljava / lang / Object; Ljava / lang / Object;)([JavaScript object(445),JavaScript object(240),JavaScript object(637)]):parent为null

所以我添加了这个来覆盖事件,如果我想要避免事件:

        @Override
        public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,
                Element parent, YourObject object, NativeEvent event) {
            if (object.isCompleted())  
                super.onBrowserEvent( context, parent,  object,  event);
        }

我不知道这是否是更好的方法,但它有效。