table add new column dynamically

Hi,

Is it possible to add new column to table with containerDataSource(SQLContainer)? In this added column user puts new data and I save these data as new row in table. I found method addGeneratedColumn but I cannot understand how can I implement adding new column virtually…

I devised other idea for it. I write dynamically created textfields with labels on Panel like that:

label1 textfield1 label4
label2 textfield2 label5
label3 textfield3 label6

These labels contains data from DB.

But this solution is ugly…

Best regards,
Paul

Not sure how the SQL container would react to it but you can try container.addContainerProperty(propertyId, type, default); and see if it works or not.

Hi,

I tried do with your solution but it doesn’t work. I’ve got exception:

java.lang.UnsupportedOperationException
at com.vaadin.data.util.sqlcontainer.SQLContainer.addContainerProperty(SQLContainer.java:1341)

I put in code:
TableQuery tq = new TableQuery(“table1”, connectionPool, new MSSQLGenerator());
container = new SQLContainer(tq);
container.addContainerProperty(“test1”, Label.class, null);

I tried add:
table.setEditable(true);
table.addContainerProperty(“test1”, Label.class, “-”);

And I’ve got the same error:

java.lang.UnsupportedOperationException
at com.vaadin.data.util.sqlcontainer.SQLContainer.addContainerProperty(SQLContainer.java:1341)

I tried search on archive forum, I found:

https://vaadin.com/book/-/page/components.table.html#components.table.columngenerator

But it doesn’t have container data source like that: SQLContainer.

Best regards,
Paul

I don’t know exactly what you mean but the following should work:

table.addGeneratedColumn("mycolumn", new ColumnGenerator() {
	public Object generateCell(Table source, Object itemId, Object columnId) {
		TextField tf = new TextField();
		return tf;
	}
});