Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Table cell in-line editing
The Table class is very useful for displaying data, but if I want to make something editbale i looks and behaves terribly. I'm new to Vaadin so maybe I just misunderstood someting:
1) Can I mark columns as editbale or not?
2) Can I make only the selected/focused row editable?
3) Can I make a single cell editable only when I select it?
4) If the standard Table class can't do this, is there some add-on that can?
/Anders
Hi,
1) Yes, you can.
2) Yes, you can.
3) Not sure....
;-)
Have a look at the TableFieldFactory usage.
table.setTableFieldFactory(new TableFieldFactory () {
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
TextField field = new TextField((String) propertyId);
// If you want to disable edition on a column, use ReadOnly
if ("Not Editable".equals(propertyId))
field.setReadOnly(true);
else { // The numeric column
// The field needs to know the item it is in
field.setData(itemId);
}
// You can also add condition on itemId & current selection
//ex for a mono selection table:
if(table.getValue() != null && table.getValue().equals(itemId))
{
field.setReadOnly(false);
}
else
{
field.setReadOnly(true);
}
return field;
}
});
//Don't forget to set your table editable, otherwise the TableFieldFactory won't be used
table.setEditable(true);
Hope it helps
Thanks for helping... I suppose I should have read the Table chapter in the Book of Vaadin before posting that question. It even states in the first paragraph that "clicking on a cell could change it to a text field for editing". Browsing through the chapter I don't think the author was explicit about how he recommends that to be implemented, but I can see that it's possible.
Now that I know a little more I don't think using a Table with editable columns/cells suits my needs - seems messy and backwards to implement. Starting from scratch with a GridLayout seems much "easier".
/Anders
Anders Peterson: Thanks for helping... I suppose I should have read the Table chapter in the Book of Vaadin before posting that question. It even states in the first paragraph that "clicking on a cell could change it to a text field for editing". Browsing through the chapter I don't think the author was explicit about how he recommends that to be implemented, but I can see that it's possible.
Now that I know a little more I don't think using a Table with editable columns/cells suits my needs - seems messy and backwards to implement. Starting from scratch with a GridLayout seems much "easier".
/Anders
Hi Anders Peterson,
How you achieve "clicking on a cell could change it to a text field for editing". Please post your code. I am trying to achieve this for long time. But still I cant.
Thanks,
Prasath
Actually it's quite easy... (depending on exactly what you require) I use generated columns. Have the ColumnGenerator return a TextField that listens to FieldEvents.FocusListener and FieldEvents.BlurListener and set the read only flag as needed.
/Anders
void addGeneratedColumn(Object id, ColumnGenerator generatedColumn)