Reputation: 107
I need to convert values in column "anzahl" to links or buttons, and l am struggling with the structure of vaadin table. I am getting database values from mysql table name "SYSTEM" (within entity class System).
This is my table properties which l have defined:
private void initSystemTable() {
JPAContainer<System> systems = new SystemServiceDB().getAllSystems();
table_system.setSizeFull();
table_system.setContainerDataSource(systems);
table_system.setVisibleColumns(new Object[] { "softwarebezeichung", "version", "anzahl", "lizenzen" });
table_system.setColumnHeader("softwarebezeichung", "Softwarebezeichung");
table_system.setColumnHeader("version", "Version");
table_system.setColumnHeader("anzahl", "Anzahl");
table_system.setColumnHeader("lizenzen", "Vorhandene lizenzen");
table_system.setImmediate(true);
}
and class SystemServiceDB:
public class SystemServiceDB implements SystemService{
@Override
public JPAContainer<System> getAllSystems()
{
JPAContainer<System> systems = JPAContainerFactory.make(System.class, "help-pu");
return systems;
}
}
This is my output table:
I can't use addContainerProperty
to set the column as l load these values from mysql, I can't find the way to solve this problem. I will appreciate if anyone can help me to solve this.
table_system.addContainerProperty("anzahl", Link.class, null);
table_system.addContainerProperty("anzahl", Button.class, null);
Upvotes: 0
Views: 525
Reputation: 722
Use generated columns.
This is an example of a generated column with a button:
table.addGeneratedColumn("generated", new ColumnGenerator() {
@Override
public Component generateCell(Table source,
final Object itemId, Object columnId) {
Button button = new Button("caption");
//Listener for the button
button.addClickListener(Event -> {
//Your code
});
return button;
}
});
Upvotes: 4