2011-08-11 1 views
4

私のテーブルの列の1つにdeleteButtonを設定したいと思います。CellTableの列にカスタムActionCellを作成する

ActionCell<Entrata> deleteCell = new ActionCell<Entrata>("x",new Delegate<Entrata>() { 
      @Override 
      public void execute(Entrata object) { 
       // rpc stuff.... 
      } 
     }); 

[OK]をしかし、この行はエラーを生成します。

Column<Entrata,Entrata> deleteColumn = new Column<Entrata, Entrata>(deleteCell); 

あなたはどう思いますか "型の列をインスタンス化できませんか"? DOKUから

答えて

0

ここでは、作業のコードで行く:

仮定:

TYPE - 私はあなたがインスタンスへの参照をしたいと仮定しているため、それと同じあなたがCell表の列に表示されるデータのクラスですデータのときに

public class DeleteColumn extends Column<TYPE, TYPE> 
{ 
    public DeleteColumn() 
    { 

     super(new ActionCell<TYPE>("Delete", new ActionCell.Delegate<TYPE>() { 
      @Override 
      public void execute(TYPE record) 
      { 
       /** 
        *Here you go. You got a reference to an object in a row that delete was clicked. Put your "delete" code here 
        */ 
      } 
     })); 
    } 

    @Override 
    public TYPE getValue(TYPE object) 
    { 
     return object; 
    } 
}; 
+0

それをCellTableに追加する方法は? 私はそれを行うことができましたが、アクションセルをクリックするとClassCastExceptionが発生します。 – Ben

+0

@UiField CellTable listTable; listTable.addColumn(新しいDeleteColumn()、 "Delete"); –

0

Column<String, String> colum = new Column<String, String>(null) { 

     @Override 
     public String getValue(String object) { 
      // TODO Auto-generated method stub 
      return null; 
     } 
    }; 

それでも私は正確にあなたが削除ボタンを実装方法がわからないので、それは次のようになります。

A representation of a column in a table. The column may maintain view data for each cell on demand. New view data, if needed, is created by the cell's onBrowserEvent method, stored in the Column, and passed to future calls to Cell's

だから、あなたはそれをこのような何かをDECLARする必要があなたのコードの残りの部分を私たちに与えることができればうれしいです。

0

これは

//table = initialized CellTable with content already loaded 

ActionCell editCell = new ActionCell<EmployeeObject>("remove", new ActionCell.Delegate<EmployeeObject>() { 
      public void execute(EmployeeObject object){ 
       List<EmployeeObject> list = new ArrayList<EmployeeObject>(table.getVisibleItems()); 
       for(int i = 0; i < list.size(); i ++){ 
        if(object.getFirstname().equals(list.get(i).getFirstname())){ 
         list.remove(i); 
         break; 
        } 
       } 
       table.setRowData(list); 
      } 
     }); 

Column<EmployeeObject, ActionCell> editColumn = (new IdentityColumn(editCell)); 
を作品にそれを削除しようとして