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.
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).
Oops sorry for the delayed response.
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.