Grid: access item properties from Renderer

Hi everyone.

I’m wondering if it’s possible to access Grid item (row) properties from the custom Renderer.
I would like to replace Table with Grid, and I’m investigating if it’s possible to remain the same look and feel.
In my table I have custom Table.ColumnGenerator that generates cells for the column (property) based on the another column’s value for the same item.
To make it clearer, here is the code snippet

@Override public Object generateCell(Table source, Object itemId, Object columnId) { Item item = source.getItem(itemId); Object cellValue = item.getItemProperty(columnId).getValue(); boolean flag = (boolean) item.getItemProperty("flag").getValue(); String content = SomeUtils.formatAsHtml(cellValue, flag); return new Label(content, ContentMode.HTML); } So based on the value of the “flag” property I get different HTML that I would like to display in a table cell.
Is it possible with Grid or it’s better to have Table?
Thanks in advance
Alex

It’s even easier:

     GeneratedPropertyContainer container = new GeneratedPropertyContainer(myContainer);  
     container.addGeneratedColumn("myProperty", new PropertyValueGenerator<String>() {

            @Override
            public String getValue(Item item, Object itemId, Object propertyId) {
                 Object cellValue = item.getItemProperty(columnId).getValue();
                 boolean flag = (boolean) item.getItemProperty("flag").getValue();
                 return SomeUtils.formatAsHtml(cellValue, flag);
            }
            @Override
            public Class<String> getType() {
                return String.class;
            }
     }
     table.setContainerDataSource(container);
     grid.getColumn("myProperty").setRenderer(new HtmlRenderer());

Hi Agata.

What version of Vaadin do you mean?
I’m not able to find method ‘addGeneratedColumn’ in Grid in versions up to 7.7.6
Also in
this article
I found the following in the section
Differences to Table
: Grid has no generated columns.
May be I’m missing something. Could you please get more detais on your example.

Thank you!

I’m sorry Alex. Because my code is a bit complicated, my extraction was not perfect ;-). Please see my updated unswear (you need to use
GeneratedPropertyContainer,
that wraps your original container).

Now it’s clear.
Thanks for update!