# Table Cell Background Color Not Updating When Using Variable

**URL:** <https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 18, 2025, 11:58am UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749 "2025-09-18T11:58:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechEnlive](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@TechEnlive](https://forum.inductiveautomation.com/u/TechEnlive)\
**Post date:** [September 18, 2025, 11:58am UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/1 "2025-09-18T11:58:55Z")

</div>

Hi everyone,

I have a function that updates the background color of a table cell using a parameter called `colorlung`. Here’s the code I’m using:

```python
return {'backgroundColor': colorlung, "color": "#FFFFFF", 'borderBottom': '3px solid red'}

```

When I pass a literal color (e.g., `"#007FFF"`), it works fine. However, when I try to use a variable (`colorlung`), the cell shows up completely white and the color is not applied.

Has anyone encountered this issue before? How can I ensure the cell uses the color stored in a variable?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 18, 2025, 12:00pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/2 "2025-09-18T12:00:51Z")

</div>

Show us how you've set the variable `colorlung`.

---

<div class="post-metadata">

**Author:** ![TechEnlive](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@TechEnlive](https://forum.inductiveautomation.com/u/TechEnlive)\
**Post date:** [September 18, 2025, 12:04pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/3 "2025-09-18T12:04:52Z")

</div>

```python
def getStyle(row,col,datechange,col2,colorlung,colorspes):		
		
		if ((cellprodid==self.custom.V_tag_exefoam) and (not cellprocessed==2)): #self.custom.V_tag_exefoam bind with tag EXE_FOAM
			if (cellstopfoaming==1 and not(datechange)):
				if col2 =="INVENTCOLORID":
					return {'backgroundColor':colorlung,"color": "#FFFFFF",'borderBottom': '3px solid red'}	
				return {'backgroundColor':'#0F6635',"color": "#FFFFFF",'borderBottom': '3px solid red'}
			elif (cellstopfoaming==1 and (datechange)):
				if col2 =="INVENTCOLORID":
					return {'backgroundColor':colorlung,"color": "#FFFFFF",'borderBottom': '3px solid red','borderTop': '8px double #4227F5'}	
				return {'backgroundColor':'#0F6635',"color": "#FFFFFF",'borderBottom': '3px solid red','borderTop': '8px double #4227F5'}
			elif (datechange):
				if col2 =="INVENTCOLORID":
					return {'backgroundColor':colorlung,"color": "#FFFFFF",'borderTop': '8px double #4227F5'}
				return {'backgroundColor':'#0F6635',"color": "#FFFFFF",'borderTop': '8px double #4227F5'}
			else:
				if col2 =="INVENTCOLORID":
					return {'backgroundColor':colorlung,"color": "#FFFFFF"}
				return {'backgroundColor':'#0F6635',"color": "#FFFFFF"}	

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 18, 2025, 12:11pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/4 "2025-09-18T12:11:25Z")

</div>

Thanks. We still can't see the value you're passing into the function.

You should be able to see the problem in Designer if you expand `PROPS.data` and examine the `style` property on the problem row or cell.

On a more general note: hard-coding style like this is not the way of the web or Perspective. Instead, create a style class for each condition and let your code apply the appropriate one. Consistency is then assured across your application and changes can be made in the styles without even opening the views.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [September 18, 2025, 12:13pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/5 "2025-09-18T12:13:47Z")

</div>

Hello,

I´m using something like:

```python
# Transform (Ignition Perspective) – colorea "TEMPERATURE C" por rangos

# Paleta básica
BLUE = "#4BB4E6"
LBLUE = "#B5E8F7"
GREEN = "#50BE87"
YELLOW = "#FFD200"
ORANGE = "#FF9800"
RED = "#CD3C14"

def color_temp(c):
    if c is None: return None
    if c < 18: return BLUE
    if c < 20: return LBLUE
    if c < 24: return GREEN
    if c < 27: return YELLOW
    if c < 30: return ORANGE
    return RED

py = system.dataset.toPyDataSet(value)
cols = list(py.getColumnNames())
out = []

for r in py:
    row = {}
    # Intenta convertir a float (si viene como texto, ignora si falla)
    try: t = float(str(r.get("TEMPERATURE C")).replace(".", "").replace(",", ".")) # tolera coma decimal
    except: t = None

    for c in cols:
        cell = {"value": r[c]}
        if c == "TEMPERATURE C":
            bg = color_temp(t)
            if bg: cell["style"] = {"backgroundColor": bg}
        row[c] = cell
    out.append(row)

return out

```

to colour cells on tables and works fine.

I´m using it as a script transform of binded data to props.data

---

<div class="post-metadata">

**Author:** ![TechEnlive](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@TechEnlive](https://forum.inductiveautomation.com/u/TechEnlive)\
**Post date:** [September 18, 2025, 12:16pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/6 "2025-09-18T12:16:57Z")

</div>

Hi first thanks for coopeation,  
The rest of the code is working fine. I have checked that the “colorlung“ variable have new color code every time but when try to use in style dictionery it cause the problem.

This work (without variable):

```python
return {'backgroundColor':'#0F6635',"color": "#FFFFFF",'borderTop': '8px double #4227F5'}

```

This did not (with variable):

```python
return {'backgroundColor':colorlung,"color": "#FFFFFF",'borderTop': '8px double #4227F5'}

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 18, 2025, 12:30pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/7 "2025-09-18T12:30:59Z")

</div>

Yes, but show us what the result is.

- If you're in Designer then expand the `PROPS.data` and find the `style` prop for the affected cell or row.
- If you're in a browser then press F12 for Developer Tools and use the Inspect Button to select the affected cell and examine the properties.

> [@TechEnlive](#):
>
> ... when try to use in style dictionery ...

What do you mean by "style dictionary"?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 18, 2025, 12:33pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/8 "2025-09-18T12:33:32Z")

</div>

> [@Alejandro\_Alaco](#):
>
> I´m using something like:
> 
> ```python
> # Transform (Ignition Perspective) – colorea "TEMPERATURE C" por rangos
> 
> # Paleta básica
> BLUE = "#4BB4E6"
> LBLUE = "#B5E8F7"
> 
> ```

Bad boy. Use style definitions. Don't hard code1.

1 There are times when you have to. The AM Charts components don't recognise CSS variables, for example. In that case I would create the color options as a session variable object and name each by what it represents rather than color (like the `--success` and `--error` theme variables, for example).

---

<div class="post-metadata">

**Author:** ![TechEnlive](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@TechEnlive](https://forum.inductiveautomation.com/u/TechEnlive)\
**Post date:** [September 18, 2025, 12:40pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/9 "2025-09-18T12:40:42Z")

</div>

Thanks a lot, Transistor!

It turns out there was a miscalculation in one of my `if` conditions. The data was formatted in Italian style as `3.800`, and when I converted it to a float, it became `3.80` instead of `3800.00`. I’ve fixed the conversion, and now everything is working fine.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 19, 2025, 4:01pm UTC](https://forum.inductiveautomation.com/t/table-cell-background-color-not-updating-when-using-variable/110749/10 "2025-09-19T16:01:19Z")

</div>

As an aside, I'd find a rewrite like this to be a lot more readable/maintainable over time. Instead of building the whole dictionary in each possible branch, just make the corresponding updates in each branch, so if you want to add more conditions it's a lot easier and less error prone:

```python
def getStyle(row, col, datechange, col2, colorlung, colorspes):
	if (cellprodid == self.custom.V_tag_exefoam) and (not cellprocessed == 2):
		# 1. Define a base style dictionary.
		style = {
			'backgroundColor': colorlung if col2 == "INVENTCOLORID" else '#0F6635',
			'color': '#FFFFFF'
		}

		# 2. Imperatively update the dictionary for conditional styles.
		if cellstopfoaming == 1:
			style['borderBottom'] = '3px solid red'
		
		if datechange:
			style['borderTop'] = '8px double #4227F5'
		
		# 3. Use a single return statement.
		return style

	# Else: Return empty dictionary to avoid dereferencing null
	return {}

```
