Table Cell Link

I want to be able to have a link in a cell that does some action with the row entity. e.g. send an email.

Invoice ID ---  View Invoice --- Send Invoice
1     Invoice.pdf    Email Invoice

In my example I have a list of invoices and I want to be able to send an email reminder to that person by clicking a cell on the table. Can’t quite figure out how to do this.

I managed to get it to generate a button in the cell but can’t figure out how to add an action.

Hope this makes sense.

I think i am getting somewhere:

public Component cellGenerator(Invoice entity) {

        WebButton webButton = new WebButton();
        webButton.setCaption("Email Invoice");
        webButton.setAction(doSomething(entity));
		return webButton;
    }

I am wondering how to put an action to each button that remembers what invoice the button is sending.

Have added a pic to show what I want

123

Nevermind…

Managed to resolve by reading various docs.

Here is what I managed to figure out:

 @Override
    public void init(Map<String, Object> params) {
        invoicesTable.addGeneratedColumn("Email Invoice", new Table.ColumnGenerator() {
            @Override
            public Component generateCell(Entity entity) {

                  WebButton field = (WebButton) componentsFactory.createComponent(WebButton.NAME);
                field.setCaption("Send Email");
               field.setAction(new BaseAction("hello") {
                    @Override
                    public void actionPerform(Component component) {
                       emailInvoice((Invoice)entity);
                    }
                });
                return field;
            }
        });
    }

Hi,

You can improve your solution:


@Inject
protected Table<User> usersTable;
//...
usersTable.addGeneratedColumn("Email Invoice", entity -> {
    LinkButton field = componentsFactory.createComponent(LinkButton.class);
    field.setCaption("Send Email");
    field.setAction(new BaseAction("hello")
            .withCaption("Hello")
            .withHandler(event -> {
                emailInvoice(entity);
            })
    );
    return field;
});

Inject Table with Entity type and use createComponent with class of a Component. Also, BaseAction has a couple of convenient methods, for instance with lambda handler.

1 Like