Vaadin8 Grid - Where is setCellStyleGenerator ?


I am trying to set the sytle of a grid cell dynamically, based on the value of a cell in a row above it ( the grid shows a list of versions of an object and I want to highlight a cell where there is a difference with its previous version value ).
I was looking at setCellStyleGenerator as an option but it is gone in Vaadin 8 …
setStyleGenerator will not work since in the apply method, I don’t have visiblity to the rest of the grid data and cells.

Any ideas ?
Many thanks.


I think you’ll need to look up the data from outside of the Grid.


Thanks Oili but not sure I follow you - what do you mean “from outside the grid” ?
Can you explain more or point to an example ?

Many thanks

I mean, instead of looking for the previous value from the Grid in setStyleGenerator(), look for it from the DataProvider or however it is that you populate the data in your Grid.


Thanks for the prompt reply - so just to make sure I understand your suggestion, in the StyleGenerator apply method,scan the relevant data in my data provider and set the style accordingly ?

Yep, that’s the idea!

What about

Matic - this is exacatly what I used, only in previous versions of Vaadin, only in earlier version a
method was avaiable which inluded the cell infromation so one could traverse the grid and get other cells infromation.

Anyway, based on Olli’s direction (Thanks man ! ) I ended up with this code which seems to work fine and is not too ugly :slight_smile:

For each relevant coloumn :

grid.addColumn(ShippingHistory::getHwRevision).setCaption(“Hardware Revision”).
setStyleGenerator(new DiffStyleGenerator(ShippingHistory::getHwRevision));

grid.addColumn(ShippingHistory::getSwRevision).setCaption(“Software Revision”).
setStyleGenerator(new DiffStyleGenerator(ShippingHistory::getSwRevision));

And my style generator class :

public class DiffStyleGenerator implements StyleGenerator<ShippingHistory> {
    private Function<ShippingHistory, ?> theGetter = null;

    public DiffStyleGenerator(Function<ShippingHistory, ?> f) {
        theGetter = f;
    public String apply(ShippingHistory item) {
        String retVal = null;
        Long itemVer = item.getVersion();

        if (itemVer > 0) {
            ShippingHistory prevVer = allItems.get(itemVer.intValue()-1);
            if (theGetter.apply(item) != null) {
                if (!theGetter.apply(item).equals(theGetter.apply(prevVer))) retVal = "t-highlight-cell";
        return retVal;


Comments are of course welcome.

Many thanks for all your help !

Thank you davehel. Yesterday I solve this problem the some way.

I am facing the same problem:

I added to my mytheme.scss the following:

.v-grid-row.highlight-red {
background-color: #FF6d73;

And for the grid:
grid.setStyleGenerator(statusImport → {
if (!statusImport.getStatus().equals(1)) {
return “highlight-red”;
return null;

But, the row is not red…

The example at the Vaadin Book at Grid also does not work for me. Did I place my css in the wrong place?
Trying it with a column does also not work:

addColumn(StuecklistenStatusImport::getMenge).setStyleGenerator(menge → “align-right”).setCaption(“Menge”);

Any ideas?


My first guess is to clear the browser history as the css file is cached and won’t change unless you clear the browser cache.
My second guess is that the scss file is either not located correctly or not compiled well.
The documentation in the Vaadin book is not great, I struggled with it also.

I Ended up putting my theme folder under the resources folder ( see my theme (telco) folder structure in the attached pic ) and added a compilation goal in my maven file :


-Xmx2G -Xss1024k


Hope this helps !


I have the some problem. My solution (it works) :

.mytheme .v-grid-row-working > td {
background-color : rgba(255, 118, 0, 0.45) !important

and then
workOrderGrid.setStyleGenerator(wo → { return return “v-grid-row-working” });

I think the trick is background color must be on td element.

Hi davehel, Matic,
is seems, both of you are right. It was a cache issue and the > td did its job.


Matic, thank you a lot!
I spend almost a day trying to implement row highlighting.
Your “> td” trick make me happy.
Wonder why this idea is not in the Vaadin book/tutorial?

David, i have a question, how i can paint a cell by position for example cell(a,b), thanks for your time

I faced with the same issue on Vaadin 8: I just wanted to repaint cells in colors depending on cell values.
Solved it in next way(it works):

grid.addColumn(auditStatus -> {
	final StageCompletenessStatusDto stageDto = auditStatus.getStages().get(stage);
	return stageDto.getFinishedSubTasksCounter() + "/" + stageDto.getOverallSubTasksCounter();
}).setCaption( -> {
	final StageCompletenessStatusDto stageDto = auditStatus.getStages().get(stage);
	if (stageDto.getFinishedSubTasksCounter() == 0) {
		return "gray";
	if (stageDto.getOverallSubTasksCounter() == stageDto.getFinishedSubTasksCounter()) {
		return "red";
	} else {
		return "yellow";

The problem is Vaadin has applied !important on the v-grid-cell’s css…it overrides row’s css. Wonder why nobody told them its bad practice to use !important.