gwtbuttoncellgwt-2.2-celltable

Creating custom ActionCell in CellTable Column


I want one of my table columns to have a deleteButton.

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

Ok but this line generates an error:

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

"Cannot instantiate the type Column"

What do you think?


Solution

  • Here you go with working code:

    Assumptions:

    TYPE - Is the class of the data you show in rows of Cell Table it the same because I assume you want reference to the instance of data when you going to delete it

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