# Changing colour of row based off value in cell in perspective table

**URL:** <https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 18, 2021, 7:51pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587 "2021-02-18T19:51:52Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![splata](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@splata](https://forum.inductiveautomation.com/u/splata)\
**Post date:** [November 17, 2022, 10:23pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/21 "2022-11-17T22:23:28Z")

</div>

what is the property just for the text color?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 17, 2022, 10:34pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/22 "2022-11-17T22:34:02Z")

</div>

`color`

---

<div class="post-metadata">

**Author:** ![splata](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@splata](https://forum.inductiveautomation.com/u/splata)\
**Post date:** [November 17, 2022, 10:42pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/23 "2022-11-17T22:42:37Z")

</div>

I thought that when I saw the text properties but in practice it is not possible, just change that property for the \_id

 ![imagen](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/01e37bb2e502ade9580e25bc3e5839c1390dca9d.png)

```auto
Status=row.C15
		if Status=="NO ANSWER" and row['Origen']== "Externo" :
			row['_id']= {'value': row['_id'], 'style': {'Color': '#FFCCCC'}}
			row['Origen']= {'value': row['Origen'], 'style': {'backgroundColor': '#FFCCCC'}}
			row['Destino']= {'value': row['Destino'], 'style': {'backgroundColor': '#FFCCCC'}}
			row['C10']= {'value': row['C10'], 'style': {'backgroundColor': '#FFCCCC'}}
			row['C14']= {'value': row['C14'], 'style': {'backgroundColor': '#FFCCCC'}}
			row['C15']= {'value': Status, 'style': {'backgroundColor': '#FFCCCC'}}
			row['C17']= {'value': row['C17'], 'style': {'backgroundColor': '#FFCCCC'}}
			row['file']= {'value': row['file'], 'style': {'backgroundColor': '#FFCCCC'}}
	    
		OutputJson.append(row)
	    
	return OutputJson

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 17, 2022, 11:08pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/24 "2022-11-17T23:08:35Z")

</div>

It works for me.

 ![Screenshot 2022-11-17 at 3.08.05 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79b0767d7c67935ca90eb0bbc5a942651e9965bb.png)

---

<div class="post-metadata">

**Author:** ![splata](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@splata](https://forum.inductiveautomation.com/u/splata)\
**Post date:** [November 17, 2022, 11:18pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/25 "2022-11-17T23:18:14Z")

</div>

it´s working now. is sensitive to Upercase

---

<div class="post-metadata">

**Author:** ![Eric\_Gruber](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eric_gruber/32/51070_2.png) [@Eric\_Gruber](https://forum.inductiveautomation.com/u/Eric_Gruber)\
**Post date:** [August 15, 2023, 5:35pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/26 "2023-08-15T17:35:18Z")

</div>

Perfect! That is exactly what I was looking for!

---

<div class="post-metadata">

**Author:** ![Ivan\_Herrera](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Ivan\_Herrera](https://forum.inductiveautomation.com/u/Ivan_Herrera)\
**Post date:** [June 14, 2024, 8:10pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/27 "2024-06-14T20:10:14Z")

</div>

Hello, Could you please help me idetify where should I use the code?  
I have a table from a SQL query in Dataset form.

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 14, 2024, 8:39pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/28 "2024-06-14T20:39:58Z")

</div>

Go watch this video: [Cell color related to content in Ignition Perspective - #8 by danieltalbot](https://forum.inductiveautomation.com/t/cell-color-related-to-content-in-ignition-perspective/89269/8)

---

<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:** [June 14, 2024, 10:51pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/29 "2024-06-14T22:51:09Z")

</div>

Welcome to the forum, Ivan.  
For anyone to test or correct your code they would have to type it all out again. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

Also, if you hover over the **Error\_ScriptEval** message at the bottom of the dialog it will give you a good clue to the nature of the problem. Be sure to include the error details when seeking help.

---

<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:** [June 15, 2024, 6:07pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/30 "2024-06-15T18:07:48Z")

</div>

A few things:

- first take a few basic python courses, or read some tutorials. It might seem boring now, but you need to invest that time to be more efficient and not rely on forums for the most simple errors in the future
- Indent everything properly:  
The whole thing is indented with 2 tabs, which is not a problem in itself as long as the indentation is consistent. But I suggest you take it back to one tab only.  
now, notice how the `if` and `else` are not on the same indentation level ? That's an issue. Scope is based on indentation in python, so here your `if` and `else` are NOT related. Which means you have an `else` without an `if`. And that's an error
- You're returning in the loop. While not an error it itself, it really is NOT what you want to be doing here.
- It seems you're applying the same style to every cell in the row. You can apply style to the row directly, it will make things much simpler to write, read, and maintain. It might also be more efficient.
- The whole point of a default is that you don't need to do anything. You don't need to apply nothing to get the default style. Actually, you might even be overriding it with nothing (I think it's not the case here, but the point still stands).

So, I'd suggest changing the return type of the query binding to `json`, and then you can do this:

```python
acked_style = {'backgroundColor': "#00ff00"}
output = []
for row in value:
	r = {'value': row}
	if row['ACK_BY'] == "":
		r['style'] = acked_style
	output.append(r)
return output

```

Or, you can do this:

```python
acked_style = {'backgroundColor': "#00ff00"}
headers = value.columnNames
data = [{'value': dict(zip(headers, row))} for row in system.dataset.toPyDataSet(value)]
for row in data:
	if row['value']['ACK_BY'] == "":
		row['style'] = acked_style
return data

```

last edit: just for fun:

```python
return [dict(row, **({'style':{'backgroundColor': "#00ff00"}} if row['value']['ACK_BY'] else {})) for row in ({'value': dict(zip(value.columnNames, row))} for row in system.dataset.toPyDataSet(value))]

```

yes I did make it more complicated than it actually needs to be...but that's part of the fun.

---

<div class="post-metadata">

**Author:** ![Learner\_Ignition](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Learner\_Ignition](https://forum.inductiveautomation.com/u/Learner_Ignition)\
**Post date:** [November 29, 2024, 12:51pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/31 "2024-11-29T12:51:59Z")

</div>

Hi  
I am trying to implement same features to my table and I am getting an output as

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9a0fd906fe3ab6abb0e76cb8d8ab83ebaa583a15.png)

Can anyone guide me what is going wrong, as with this output Table row color is not changing.

Thanks

---

<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:** [November 29, 2024, 1:19pm UTC](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587/32 "2024-11-29T13:19:15Z")

</div>

Your `style` object is OK.  
You just need to move everything else into a `value` object.

 ![Table row style](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/e/ee6e5d305cadd18aba8951e60bf6961b8cf2e524.png)

Tip: start using the [Built-in Theme Colors](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes#built-in-theme-colors).

[Previous page](https://forum.inductiveautomation.com/t/changing-colour-of-row-based-off-value-in-cell-in-perspective-table/43587.md?page=1)
