Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
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<Person>, 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
Nicklas Karlsson: 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<Person> 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. :|
Say I have:
Grid<Person> 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.
Martin Vyšný: 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!
jr.2:
Martin Vyšný: 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 :)