# Scripting Row Background color

**URL:** <https://forum.inductiveautomation.com/t/scripting-row-background-color/19738>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [September 19, 2018, 6:53pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738 "2018-09-19T18:53:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 19, 2018, 6:53pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/1 "2018-09-19T18:53:38Z")

</div>

So I have gotten a little stuck in scripting for changing the background color of entire rows in a table (I am using a standard table not a Power table).

I would like it to iterate through the rows of my existing table and change the background of specific rows using conditional statements. This code is executed using a button.

I am uncertain how to go about this, but this is my best guess about how I think the code might go

```auto
event.source.parent.getComponent('TableT3').data = dataOut

for row in dataOut:
    rowData = list(row)
	if row[4] == "11/9/2018":
		event.source.getComponent("TableT3").background = system.gui.color("Red")
	if row[4] == "11/8/2018":
		event.source.getComponent("TableT3").background = system.gui.color("Yellow")
	if row [4] == "11/7/2018":
		event.source.getComponent("TableT3").background = system.gui.color("Green")

```

An error message appears for the for loop: Object is not able to iterate

Thanks in Advance

---

<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:** [September 19, 2018, 8:08pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/2 "2018-09-19T20:08:27Z")

</div>

try changing dataOut into a pydataset before iterating…

```auto
pydata = system.dataset.toPyDataSet(dataOut) 
```

---

<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:** [September 19, 2018, 8:09pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/3 "2018-09-19T20:09:29Z")

</div>

also it should be

```auto
 dataOut = event.source.parent.getComponent('TableT3').data 

```

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 19, 2018, 8:26pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/4 "2018-09-19T20:26:39Z")

</div>

That seemed to assist with the beginning of the for loop, but I still get an error in this line of code

> [@agweb.salinas](#):
>
> event.source.getComponent("TableT3").background = system.gui.color("Red")

Error Message: 1st arg can't be coerced to int

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [September 19, 2018, 8:35pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/5 "2018-09-19T20:35:30Z")

</div>

On those lines, you’re missing a .parent before getComponent like you have in the dataOut assignment. Add that and you should be good to go.

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 19, 2018, 8:57pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/6 "2018-09-19T20:57:03Z")

</div>

Ah good catch! I feel dumb. Thanks for your guy’s help

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 20, 2018, 4:32pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/7 "2018-09-20T16:32:49Z")

</div>

I am having a new problem however. When a input all of the same date in, it turns them the correct color. However if I mix and match dates it defaults to the yellow color. Does anyone know why this is?

For what I can tell its taking the last date in the table then making the rest of the rows correspond to the date color.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 20, 2018, 5:44pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/8 "2018-09-20T17:44:16Z")

</div>

Your script is setting the background color of the entire table, not the color of a row.

Coloring individual cells or rows is much more difficult to do on a standard table as opposed to a power table.

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [September 20, 2018, 5:57pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/9 "2018-09-20T17:57:03Z")

</div>

Is it possible to do on a standard table? And do you know how to go about doing it?

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 20, 2018, 6:01pm UTC](https://forum.inductiveautomation.com/t/scripting-row-background-color/19738/10 "2018-09-20T18:01:00Z")

</div>

You would need to use the table customizer.

[https://docs.inductiveautomation.com/display/DOC79/Table+Customizer](https://docs.inductiveautomation.com/display/DOC79/Table+Customizer)
