Grid remove columns won't remove properties from container data source whic

I have grid component which displayes data based on other component value. The columns in grid varies depends on selection. When I remove all the columns and try to load the grid with new columns its throws below exception

java.lang.IllegalArgumentException: There are 28 visible columns, but 4 cell values were provided.
at com.vaadin.ui.Grid.addRow(

Below is the code:


for(String header : presenter.getHeaders()){

for(Map.Entry<PS, List<Double>> result : presenter.getResult().entrySet()){
List<String> tempList = new ArrayList<String>();
PS ps = result.getKey();
for(Double value : result.getValue()){
}catch(Exception e){

This happens only once when I initially change the columns. afterwards changing columns works fine. How to resolve this issue? any pointers?



It is by design that grid will never remove any actual properties from the container. If you want to remove them, you will need to access the container directly. However Grid will notice if you remove a property from the container and will remove the corresponding column for you.


I am removing the columns from container as well. resultGrid.getContainerDataSource().removeAllItems(); However, this also won’t remove the columns. Am I missing anything? is there any other way to remove the columns from container?

Removing items doesn’t remove properties. Properties are determined by Beans of the BeanItemContainer. So you need to remove the container data source alltogether and replace it with new BeanItemContainer of different Bean type, with different set of properties.

The default Container also has .removeContainerProperty(Object propertyId) which you can use to remove the properties from the Container. To clear all of them you can do: for (Object propertyId : container.getContainerPropertyIds()) { container.removeContainerProperty(propertyId); }

Thanks for your reply. conceptually it works well but code below throws ConcurrentModificationException which I solved by copying the propertyIds in seperate collection and then removing property by iterating over new collection.

for (Object propertyId : container.getContainerPropertyIds()) {

I’m getting an UnsupportedOperationException while trying to accomplish this on an SQLContainer; any hints?

I’ve already “covered” this case by setting the offending columns to hidden and making them (un)unhidable, via .setHidden() and .setHidable(). But I do feel like the proper way would be at the datasource level.