# How we setup color formatting in particular column's value in table

**URL:** <https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685>\
**Category:** General Discussion\
**Tags:** ignition81, perspective\
**Created:** [September 27, 2023, 4:35am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685 "2023-09-27T04:35:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohd\_Waqas](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Mohd\_Waqas](https://forum.inductiveautomation.com/u/Mohd_Waqas)\
**Post date:** [September 27, 2023, 4:35am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/1 "2023-09-27T04:35:48Z")

</div>

we need to setup color formatting in particular 1 columns value like if columnname\<35% - red,columnname\>35% and columnname\<60% -yellow and columnname\>60%-green

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 27, 2023, 9:30am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/2 "2023-09-27T09:30:56Z")

</div>

What do you want to color, the whole row or just a particular cell ?  
What's the data format/source ? You'll need to format the whole thing to json I believe.

Taking the example table (except changing Folsom's format to have consistent formatting) and making its rows red/green depending on population:

```python
color = lambda row: "red" if row['population'] > 1000000 else "green"
return [
	{
		k: {
			'value': v,
			'style': {'background-color': color(row)}
		} for k, v in row.iteritems()
	} for row in value
]

```

If you're pulling data from a query, you can just change its return format to json then add this script as a transform. And obviously change the `color` lambda to match your conditions and colors.

Note: I pulled the color selection logic out to make it easier to separate the logic that builds the data structure and the one that selects a color, but it would probably be a good idea to inline it once you understand how it works:

```python
return [
	{
		k: {
			'value': v,
			'style': {'background-color': "red" if row['population'] > 1000000 else "green"}
		} for k, v in row.iteritems()
	} for row in value
]

```

---

<div class="post-metadata">

**Author:** ![Mohd\_Waqas](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Mohd\_Waqas](https://forum.inductiveautomation.com/u/Mohd_Waqas)\
**Post date:** [September 27, 2023, 11:31am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/3 "2023-09-27T11:31:13Z")

</div>

the whole row for particular column value and from where we need to add this script under which section and script is in python.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 27, 2023, 12:08pm UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/4 "2023-09-27T12:08:11Z")

</div>

> [@pascal.fragnoud](#):
>
> add this script as a transform

In the `data` binding, add a script transform. That's where you can script things.

---

<div class="post-metadata">

**Author:** ![Mohd\_Waqas](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Mohd\_Waqas](https://forum.inductiveautomation.com/u/Mohd_Waqas)\
**Post date:** [September 29, 2023, 5:47am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/5 "2023-09-29T05:47:22Z")

</div>

can you give proper script ?

---

<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 29, 2023, 6:54am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/6 "2023-09-29T06:54:45Z")

</div>

There are examples in the documentation.

[Perspective - Table - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table#PerspectiveTable-Examples).

Work through those, testing them in Designer so that you understand them fully before attempting to write your own. Then come back here if you can't get Pascal's code to work.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 29, 2023, 8:56am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/7 "2023-09-29T08:56:14Z")

</div>

What do you mean, proper script ? You find the ones above "improper" ?

---

<div class="post-metadata">

**Author:** ![Mohd\_Waqas](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Mohd\_Waqas](https://forum.inductiveautomation.com/u/Mohd_Waqas)\
**Post date:** [October 3, 2023, 5:02am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/8 "2023-10-03T05:02:33Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![Mohd\_Waqas](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Mohd\_Waqas](https://forum.inductiveautomation.com/u/Mohd_Waqas)\
**Post date:** [October 3, 2023, 11:25am UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/9 "2023-10-03T11:25:59Z")

</div>

I have done with the scripting.

---

<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:** [October 3, 2023, 12:57pm UTC](https://forum.inductiveautomation.com/t/how-we-setup-color-formatting-in-particular-columns-value-in-table/79685/10 "2023-10-03T12:57:19Z")

</div>

Good.  
Don't forget to mark one of the answers as "Solution".
