I have a vaadin 14 grid and want to change the format of a date field in my grid. I was looking for some kind of renderer or a method to set the format, like the SimpleDateFormat. But i am often surprised by the creators of vaadin. They often change their api and make it worse. I tried to use a spring annotation:
@DateTimeFormat(pattern = "yyyy-MM-dd")
at the getter and at the field of the element type. But it does not work this way.The date gets rendered as "TUE Apr... " which is by far the most useless format as default. I think it is even more useless than all the vaadin versions, that force the developers to learn the same thing over and over again. It is simple until you make it complicated.
How can i change the format of dates in a grid in a vaadin 14 application?
grid.addColumn(Pojo::getBirthdate).setHeader(translate("date.of.birth"));
The Grid#addColumn
is quite versatile, as it allows to use lambda expressions. So you can easily create a method say formatDate
, that returns formatted date and then use
grid.addColumn(item -> formatDate(item.getBirthdate)).setHeader(translate("date.of.birth"));