# Change the table cell color based on value

**URL:** <https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 10, 2022, 12:24pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604 "2022-06-10T12:24:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 12:24pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/1 "2022-06-10T12:24:37Z")

</div>

Hi,

i am using normal table not power table

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5c7ff130e7870ee6e10bdef730a262aa76e6c24a.png)  
I have data in the table  
**i want to show red color for the value greater than 50 in all cells**

how to do that for normal table?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 10, 2022, 12:57pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/2 "2022-06-10T12:57:31Z")

</div>

I would use a power table if possible, but there is an extension function `getBackgroundAt` for a regular table where you could use this, YMMV

```auto
	if value > 50 and not isinstance(value,unicode):
		#print type(value)
		return system.gui.color(217,0,0)
	return defaultColor

```

You could also do this, for your specific table data

```auto
	if value > 50 and col != 0:
		return system.gui.color(217,0,0)
	return defaultColor

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:11pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/3 "2022-06-10T13:11:40Z")

</div>

> [@dkhayes117](#):
>
> ```python
> if value > 50 and not isinstance(value,unicode):
> #print type(value)
> return system.gui.color(217,0,0)
> return defaultColor
> 
> ```

i am using tag history for 36 tags . normal table loading the data in few seconds but when i tested in power table its my client got hang and its doesn't working fine

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 10, 2022, 1:16pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/4 "2022-06-10T13:16:35Z")

</div>

Works fine for me using the table’s test data 🤷‍♂️

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/7506e8a6eeedfedf762a5ab1e1b527ccc18bee71.png)

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:17pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/5 "2022-06-10T13:17:42Z")

</div>

> [@dkhayes117](#):
>
> ```python
> if value > 50 and not isinstance(value,unicode):
> #print type(value)
> return system.gui.color(217,0,0)
> return defaultColor
> 
> ```

yes tested. I just explained you why i didn't used power table

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 10, 2022, 1:19pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/6 "2022-06-10T13:19:24Z")

</div>

> [@prasath.t](#):
>
> but when i tested in power table its my client got hang and its doesn’t working fine

Show your code in the Power Table's extension functions. I'll bet you are using a gateway callout in one of them.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:20pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/7 "2022-06-10T13:20:44Z")

</div>

no code i am using just tag history

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/0/6059ee04957d2b921b7650830a1ae2c0db5f2f4d.png)  
36 tags i am using

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 10, 2022, 1:23pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/8 "2022-06-10T13:23:11Z")

</div>

Show your Power Table’s extension functions.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:26pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/9 "2022-06-10T13:26:19Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/a/fae1f847b4a0c23e4f170bcfe99dd8c9eca0c12c.png)  
nothing i added

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 10, 2022, 1:27pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/10 "2022-06-10T13:27:13Z")

</div>

> [@prasath.t](#):
>
> i am using normal table not power table

I thought you wasn't using a power table?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:28pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/11 "2022-06-10T13:28:01Z")

</div>

yes i am not using… I tired in power tables its not worked properly…pturmel asked thats y i am showing

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 10, 2022, 1:29pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/12 "2022-06-10T13:29:42Z")

</div>

How many rows does the table have? Did you try this version?

```auto
if value > 50 and col != 0:
		return system.gui.color(217,0,0)
	return defaultColor

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 10, 2022, 1:32pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/13 "2022-06-10T13:32:15Z")

</div>

No issue your code is working fine in table.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2022, 10:55am UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/15 "2022-06-16T10:55:01Z")

</div>

Hi @dkhayes117  
this is the code i am got from wincc reporting

```auto
= "#" & IIf(Int(Fields!H02.Value) < 1, "11ff",
IIf(Int(Fields!H02.Value) < 16, "ff" & Hex(17 * Int(Fields!H02.Value)),
IIf(Int(Fields!H02.Value) < 30, Hex(17 * (30-Int(Fields!H02.Value))) & "ff",
"ff11"
)
)
) & "00"

```

how to use this for power table in ignition. can you help me out what they return @paul-griffith any way to pass background color like above mentioned script in configure cell?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 16, 2022, 1:18pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/16 "2022-06-16T13:18:08Z")

</div>

That is an extremely ugly nested if that is generating a hex color code.

It looks like some test results are

```auto
'11ff00' # green H02 < 1
'ff2200' # red H02 = 2
'ffff00' # yellow H02 = 15
'ddff00' # yellow H02 = 17
'11ff00' # green H02 = 29
'ff1100' # red H02 = 31

```

There maybe a better way to do this, but without reinventing the wheel, try this

```auto
H02 = int(self.data.getValueAt(row,"H02"))

if H02 < 1:
	color = "11ff00"
elif H02 < 16:
	color = "ff%s00" % hex(17 * H02)
elif H02 < 30:
	color = "%sff00" % hex(17 * (30-H02))
else:
	color = "ff1100"

return system.gui.color(color)	

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2022, 1:53pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/17 "2022-06-16T13:53:31Z")

</div>

Thank u so much i will try and let u know

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/18 "2022-06-16T15:27:07Z")

</div>

> [@dkhayes117](#):
>
> ```python
> H02 = int(self.data.getValueAt(row,"H02"))
> 
> if H02 < 1:
> color = "11ff00"
> elif H02 < 16:
> color = "ff%s00" % hex(17 * H02)
> elif H02 < 30:
> color = "%sff00" % hex(17 * (30-H02))
> else:
> color = "ff1100"
> 
> return system.gui.color(color)	
> 
> ```

**script is not working**. Example image i have attached which i got from wincc report

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd3bf70172d357bdd727743ae2836ac9f00439ff.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 16, 2022, 3:56pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/19 "2022-06-16T15:56:07Z")

</div>

You didn’t provide enough context in order for me to give you the correct answer. My script was only looking at H02 for every row, _ **based on what you provided** _…

```auto
value = int(value)

if value < 1:
	color = "11ff00"
elif value < 16:
	color = "ff%s00" % hex(17 * value )
elif value < 30:
	color = "%sff00" % hex(17 * (30-value ))
else:
	color = "ff1100"

return system.gui.color(color)	

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/20 "2022-06-16T18:19:41Z")

</div>

> [@dkhayes117](#):
>
> ```python
> value = int(value)
> 
> if value < 1:
> color = "11ff00"
> elif value < 16:
> color = "ff%s00" % hex(17 * value )
> elif value < 30:
> color = "%sff00" % hex(17 * (30-value ))
> else:
> color = "ff1100"
> 
> return system.gui.color(color)	
> 
> ```

used your code but **color is applying for few numbers only**. **Main thing is freezing the client i couldn't able to access the window**. Is there any way to run the script without freezing client?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7c2190e82bddd6662302b8e9559707dd9f4e56d2.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 16, 2022, 6:42pm UTC](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604/21 "2022-06-16T18:42:07Z")

</div>

The hex portion of the code is adding the `0x` prefix to the number which throws off the color translation. There is most certainly a better way to fix that, but without researching it, this will fix it.

```auto
	value = int(value)
	
	if value < 1:
		color = "11ff00"
	elif value < 16:
		color = "ff%s00" % hex(17 * value).replace("0x","")
	elif value < 30:
		color = "%sff00" % hex(17 * (30-value)).replace("0x","")
	else:
		color = "ff1100"
	
	return system.gui.color(color)	

```

[Next page](https://forum.inductiveautomation.com/t/change-the-table-cell-color-based-on-value/60604.md?page=2)
