Set Table column as readonly

Hi,

I’m new with Vaadin and now I have encountered a problem :slight_smile:
How can you set a whole table column to be readonly?
I have a button that sets the table editable, but I don’t want all columns to be editable, only a few. How can I accomplish that?

I know how to set an individual cell value to be readonly, i.e. with

item.getItemProperty("columnHeader").setReadOnly(true);

but I haven’t managed to put readonly on the whole column.

Thanks!

If you are using a TableFieldFactory to create the fields for an editable table, you can set the read-only property there for each component in the particular column (property).

No, I’m not. :frowning:
Do you have an example how to create a table with TableFieldFactory and how to set the column property?

Thanks!

Here’s
an example
.

It’s also
mentioned
in the Book.

What if I want to use Label, TableFieldFactory should produce instances of Field?

If you want just to get the text like in a Label, return null from the field factory for that column/cell and, if necessary, override Table.formatPropertyValue().

If you need a Label component (e.g. for the icon), use a generated column (see Table.addGeneratedColumn()) or make a property in your data model with the type Component or Label and put your labels in the data model. I would recommend the former approach in most cases. See e.g.
this example
(somewhat larger than necessary).

Thanks for your reply, its a pity that this fact is not reflected in the
documentation

It is vaguely mentioned in
TableFieldFactory javadoc
, but I will add a comment to
javadoc ticket #4980
to clarify this.