Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add column of ClickableTextCells to cellTable

hi all i need a simple example show me how to add column of ClickableTextCells to cellTable

thanks.

like image 836
ahmed Shoeib Avatar asked Mar 21 '11 23:03

ahmed Shoeib


2 Answers

Column<YerValueObject, String> newCol = new Column<YerValueObject, String>(new  ClickableTextCell()) {
    @Override
    public String getValue(YearValueObject obj) {
        return obj.someMethod();
    }

};

newCol.setFieldUpdater(new FieldUpdater<YerValueObject, String>() {
    @Override
    public void update(int index, YerValueObject obj, String value) {
        //do whatever you need to here...
    }
});

table.addColumn(newCol, "ClickColumn");
like image 123
pigpig Avatar answered Oct 29 '22 14:10

pigpig


this is the solution if you need to add clickableTextCell to cellTable

// ClickableTextCell

ClickableTextCell anchorcolumn = new ClickableTextCell();
table.addColumn(addColumn(anchorcolumn, new GetValue<String>() {
        public String getValue(Contact contact) {
            return "Click " + contact.anchor;
        }
    }, new FieldUpdater<Contact, String>() {
        public void update(int index, Contact object, String value) {
            Window.alert("You clicked " + object.name);
        }
    }), "Anchor");



private <C> Column<Contact, C> addColumn(Cell<C> cell,final GetValue<C> getter,
FieldUpdater<Contact, C> fieldUpdater) {
        Column<Contact, C> column = new Column<Contact, C>(cell) {

        @Override
        public C getValue(Contact object) {
            return getter.getValue(object);
        }
    };
    column.setFieldUpdater(fieldUpdater);

    return column;
}

private static interface GetValue<C> {
    C getValue(Contact contact);
}


// A simple data type that represents a contact.
    private static class Contact {
        private final String address;
        private final String name;
        private final String anchor;

        public Contact(String name, String address, String anchor) {
            this.name = name;
            this.address = address;
            this.anchor = anchor;
        }
    }
like image 3
ahmed Shoeib Avatar answered Oct 29 '22 14:10

ahmed Shoeib