Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

setCellStyleGenerator - specific style according to cell value

Olga Avram
10 years ago Jan 17, 2012 11:07am
E. Yildiz
10 years ago Jan 18, 2012 8:42am

Hi

You can handle this with css. Try something like this:

table.setCellStyleGenerator(new Table.CellStyleGenerator() {
		public String getStyle(Object itemId, Object propertyId) {
			int row = ((Integer) itemId).intValue();
			int col = Integer.parseInt((String) propertyId);

			if (table.getItem(row).getItemProperty(col).getValue.equals("ANOM1") {
				return "red"
			}
			return "normal";
		}
	});

In the css you can access it with:

.v-table .v-table-cell-content-red {
	background-color: red;
}

.v-table .v-table-cell-content-normal {
	background-color: green;
}

Hope it helps.

Greets

Last updated on Jan, 18th 2012
Olga Avram
10 years ago Jan 19, 2012 9:14am
Basil Bourque
9 years ago May 31, 2012 10:02pm

Good example by E. Yildiz.

One tip: Rather than returning "normal" for your normal "do not do anything extra" case, you can return null.
So instead of this:

return "normal";

do this:

return null;

That is one less thing to remember and get right/wrong.

Jon Wells
8 years ago Jul 09, 2013 12:33pm
Marius Reinwald
8 years ago Jul 09, 2013 2:16pm
Jens Vielmann
8 years ago Dec 29, 2013 9:53pm
John Ahlroos
8 years ago Dec 31, 2013 2:27pm
Jens Vielmann
8 years ago Dec 31, 2013 4:27pm
Marko Grönroos
8 years ago Jan 01, 2014 12:30pm
Joacim Päivärinne
7 years ago Oct 17, 2014 11:12am