Vaadin8: Grid. Get Column Presentation type/class.

Hello, I’d like to know how to get the a column’s presentation class or type.

I have a generic grid, that is, I don’t create it using: Grid, but generic. I’d like to, if a cell if a BigDecimal, set a special styling.

I used to do this on vaadin7:

grid.setCellStyleGenerator(cellReference -> { if (cellReference.getValue() instanceof BigDecimal) return "align-right"; return null; }); But I can’t find a way to do it on Vaadin8.

I think you’re supposed to use setStyleGenerator on the column itself nowadays

Yes but using that, I can only get the class of the grid (Example: Grid it’ll be Person) and I need to get the presentation type. If it’s the column “age” I’d like to know the type of said column (string or int).

Can you do something with the CellReference::getValue and instanceof?

Oops sorry for the delayed response. :expressionless:
Say I have:
Grid grid.

If I try grid.addColumn(“c”).setStyleGenerator(cellReference → …). cellReference is of type “person”.
Same thing happens if I do grid.setStyleGenerator.

I’m not sure if I understand the problem, but maybe you can use column’s getValueProvider() to extract the column value out of “person”, then check that value whether it is BigDecimal:

column.setStyleGenerator(person -> {
   final Object value = column.getValueProvider().apply(person);
   return (value instanceof BigDecimal) ? "align-right" : null;
});

Grid’s setStyleGenerator applies to the entire row div element and that’s probably not what you wish for in this particular issue.

Thanks, I will try that!

Thank you Martin that was indeed what I was looking for :slight_smile: