Grid v8 Converter

Hi,

while experimenting with the new Grid (v8) API, I wondered how to set a converter on a (databound) Column.
In v7 Grid it was possible via e.g. grid.getColumn(“column”).setConverter(new StringToDateConverter());

Anybody got ideas?

You need to use Binder
https://vaadin.com/framework/whatsnew
15. Eager field validation.

Instead of .withValidator, you can use .withConverter(new StringToDateConverter())

That was my first thought too, but Binder only works for Fields, not for Grid

You want to format date in grid ?
Something like this ?:

grid.addColumn(SpisUIDTO::getDatumACasVytvoreniaSpisu,new DateRenderer(new SimpleDateFormat(ComponentsHelper.DATETIME_FORMAT))).setId(Columns.DATUMACAS_VYTVORENIA_SPISU.dtoName)

That solves the date formatting problem, but other converters still don’t work

Sorry, but theres no such thing as setConverter on Grid.Column object (APIs changed)
But you can use NumberRenderer, DateRenderer…

Yeah, I thought so, too.

Unfortunately Renderers don’t provide the same functionality as they are client side components (e.g. converting an int to an String is not possible, as far as I know).
Renderers already existed in Grid v7 parallel to Converters.

Anyway, thanks for the help.

UPDATE: I found a workaround: Adding a normal column without databinding (meaning it returns a String in the ValueProvider) gives the same functionality.

I have the same issues
https://vaadin.com/forum#!/thread/15407556

How does that work? Where do you add the converter ? on the TextField ?

grid.addColumn(item → myConverter.convertToPresentation(item.getXyz(), String.class, null)).setCaption(“Converter Column”);

I think it should be possible to change the ValueProvider or give a kind of converter after columns have been created… opened a ticket for that one: https://github.com/vaadin/framework/issues/9280