Changing the background color of a cell in Grid

Hello everybody,

I am using the basic grid from the documentation:

List<Person> people = Arrays.asList(
        new Person("Nicolaus Copernicus", 1543),
        new Person("Galileo Galilei", 1564),
        new Person("Johannes Kepler", 1571));

// Create a grid bound to the list
Grid<Person> grid = new Grid<>();
grid.addColumn(person -> Integer.toString(
        .setHeader("Year of birth");


I would like to change the background of the cells where the year is >= 1564. I saw that I could use TemplateRenderer but it renders every entry in the column. How can I specify a cell and change its background?

I will be grateful for any help.

You can use addClassNameGenerator(…) in the column and conditionally add a class name in that column.

See example here:

And how to use it in styles: