Ioannis Antonellis
Ioannis Antonellis

Reputation: 223

Change row color from cell value in google visualization table

I have a google visualization table with some numerical and some non numerical columns. I need a JavaScript function that will change the color of the whole google visualization row based on the value of a cell in the row.

I am already able to change the color of the numerical cell using the colorformater but I need to also change the color of the remaining cells of the row.

Upvotes: 8

Views: 6362

Answers (2)

user2836221
user2836221

Reputation: 1

You should set the datatable allowHtml=true.

Upvotes: -2

Pompey
Pompey

Reputation: 606

Hey I just had the same problem as you and I was able to hack together a response. I'm sure there is a better way to do this, but it works for me.

Use the data.setProperty tag and you can do that for each column of the row you are working on. So if you know the row number, which I assume you do since you can do it for just the one column using the colorformater, you can do this easily.

dataTable.setProperty(0, 0, 'style', 'background-color: red;');
dataTable.setProperty(0, 1, 'style', 'background-color: red;');

The first parameter is the row index, so that should stay constant, and the next parameter is the column index, so just loop this through all of your columns. And then you should be able to change the background-color to any css style.

Hope that helps!

Upvotes: 7

Related Questions