Reputation: 2524
I have a Vaadin Grid (myGrid) where I have enabled cell editing using
myGrid.setEditorEnabled(true);
However, I would like to disallow editing the cells in one particular column. How can I do this? The only workaround I can think of is to intercept the call to the model bean and throw some exception / show a message to the user. Is there a better way to do this?
Upvotes: 1
Views: 1885
Reputation: 15327
Take a look at my solution
indexedContainer = new IndexedContainer();
indexedContainer.addContainerProperty("name",String.class,"");
//....
//in add item process do the following
Item item = indexedContainer.getItem(indexedContainer.addItem());
item.getItemProperty("name").setValue(myModel.getName());
item.getItemProperty("name").setReadOnly(true);
//...
myGrid.setContainerDataSource(container);
that's it
I think there is another way but I did not test it
myGrid.getColumn("name").setEditable(false)
hope this helps you
Upvotes: 1
Reputation: 490
Using:
myGrid.setEditorEnabled(true);
does not automatically make every cell editable. You need to specify a Binder
for every editable column. As stated in Vaadin docs:
The editor is based on Binder which is used to bind the data to the editor. (...) For each column that should be editable, a binding should be created in the editor binder and then the column is configured to use that binding.
So if you want to disallow editing in a specific column, then just don't provide a binder for it.
Upvotes: 2