Changing the background color of individual cells in a table

Id like to be able to script or make expressions to change the background color of individual cells in a table component.

lets say you have a table component that has 4 columns. location, pressure, flowrate and battery voltage. Id like to be able to make an expression or script a way to base the background color of the cells containing the info off of the .alertactive of the particular tag residing in the cell.

I was told by support that you can either do a whole row based off of the status of a single row on the table, or you would have to go in and manually make keys, which is useless in most instances where setpoints will always be changing.

Hopefully someone knows of a way around this, because this is high priority for me!

I think you can use the basic row-mapped coloring feature for this, even though the coloring is dynamic.

The basic plan is that even though its dynamic, there is still a fixed set of colors you might want to display. For example, out of alarm, in medium alarm, in high alarm. Thats 3 states. Make a new integer column called rowState in your dataset and map the colors off of that. Now use some mechanism (either a fancy query or a script) to dynamically calculate the state for each row based on whatever dynamic criteria you please.

Sometimes the following pattern is a useful way to put this technique together:

  1. Make a Dataset dynamic property on a container. Bind it to the basic query that gets the values.
  2. Write a propertyChange script on that container looking for when your property changes. Script some logic that calculates the values of a new rowState column. Loop through the dataset, making a new dataset with this extra column.
  3. Push your newly created dataset into the Table component’s data property.

would this work for individual cells?

I am able to get the full row to fill already, but I was looking for something for individual cells.

Sorry, no, there isn’t a way to color the background of an entire cell based upon the value of another cell. The only approximation you’re going to get is using HTML formatting to color the background, but the result only colors the background of the text itself.

I think you can use TableCellRenderer, but itll be highly complicated.