Creating a custom ActionCell in a CellTable column

I want one of my table columns to have deleteButton.

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

Good, but this line throws an error:

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

"Unable to instantiate Column type"

What do you think?

+4
source share
3 answers

You will find the working code here:

Assumptions:

A TYPE. Is the data class that you show in the rows of the cell table the same because I assume that you want to reference the data instance when it is deleted.

 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
source

From the doc:

Presentation of a column in a table. A column can support view data for each cell on demand. New browsing data, if necessary, is created by the cellBrowserEvent method stored in the column and passed to future Cell calls

So you should declare it something like this:

  Column<String, String> colum = new Column<String, String>(null) { @Override public String getValue(String object) { // TODO Auto-generated method stub return null; } }; 

However, I don’t know exactly how you implement the delete button, so it would be nice if you could provide us with the rest of your code.

0
source

It works

 //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)); 
0
source

All Articles