Grid renderer for boolean?

Hello,

I am trying to render boolean column to show other values than (“true”, “false”).

I override addColumn method:

    @Override
    public Column<T> addColumn(String propertyName) {

        try {

            Class<?> type = clazz.getDeclaredField(propertyName).getType();

            ValueProvider<T, ?> vProvider = getPropertySet().getProperty(propertyName).get().getGetter();
			
            if(type.isAssignableFrom(LocalDateTime.class)){

                Column c = super.addColumn(new LocalDateTimeRenderer(vProvider, "yyyy-MM-dd HH:mm"))
                        .setKey(propertyName)
                        .setWidth("80px")
                        .setSortable(true)
                        .setComparator(vProvider);

                return c;
            }

            if(type.isAssignableFrom(Boolean.class)){

					???

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return super.addColumn(propertyName);
    }

Depends on what you want to display instead, you did not say what you want. What I did is showing the VaadinIcons CLOSE for false and CHECK for true.

I have a partial answer for you. Partial because you cant use my exact code within your override of addColumn but only works when adding the column manually to the grid. I imagine that in order to use it in your override you’ll have to adjust and generify my code a little.

grid.addComponentColumn((item) -> {
	Icon icon;
	if(item.isReady()){ // change this to your own getter for the boolean value
		icon = VaadinIcon.CHECK.create();
		icon.setColor("green");
	} else {
		icon = VaadinIcon.CLOSE.create();
		icon.setColor("red");
	}
	return icon;
})
		.setKey("ready") // set your own column key ;)
		.setComparator(Comparator.comparing(FooBar::isReady)); // change this to your own getter for the boolean value

its seems that i need to write my own BooleanRenderer…