Hiding columns from Grid

What is the preferred way to show a subset of the propertyIds of the underlying container in the new Grid?

If I have understood correctly, we are supposed to do:

Grid g = new Grid(container); g.removeAllColumns(); g.addColumn(VISIBLE_COLUMN_1) g.addColumn(VISIBLE_COLUMN_2); // ecc... But the addColumn() API says:

But isn’t this error-prone? Wouldn’t be best to raise an error if the column does not exist in the underlying container?

Read the rest of the javadoc :slight_smile:

That said, I do think the javadoc is a bit clumsily written and doesn’t make it clear there are two “modes” depending on whether the default container is used or not.


I was succesful adding columns to a table control, but now I am using a grid control and unable to add a column;

my contaner is an SQLContainer pulling data from a zimple zip code table.

here is my code:

    ZipCodeTable.getContainerDataSource().addContainerProperty("city", String.class, null);

also tried


it compiles but errors out at run time?

I assume one can add column to a Grid, can you provide some insight? sample code?

SQLContainer does not support addContainerProperty. You need a container supporting this functionality. The value of the new property must be resolved for Grid.

sorry, I am new to this can you explain what you mean by “The value of the new property must be resolved for Grid.”
maybe with a few lines of code…

else i will just stay with the table control


Hi Aron,

you have to use a Container implementing the addContainerProperty method. I never used the SQLContainer so I don’t have an idea how this QueryDelegator works but basically you should do something like this:

class MySqlContainer extends SQLContainer {
  MyQueryDelegate myDelegate; // MyQueryDelegate impelemts QueryDelegate
  public MySqlContainer(MyQueryDelegate delegate) {
    this.myDelegate = delegate;
  public void addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) {
    this.myDelegate.addProperty(propertyId, type, defaultValue);

So when normally your delegator creates a SQL like “Select a, b, c from table where d = ?” you have to manipulate your SQL when propertyId is x => “Select a, b, c, x from table where d = ?”.

Because com.vaadin.data.util.sqlcontainer.SQLContainer.propertyIds is a private property without an addPropertyId() method and the access inside SQLContainer is being called without getter you may have some problems. But I hope you got the idea.

We are using our own container implementation so luckily I already implemented the addContainerProperty method :wink: