# Power table row and cell coloring

**URL:** <https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864>\
**Category:** Ignition\
**Created:** [November 3, 2017, 2:38am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864 "2017-11-03T02:38:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![snoopyflyingace](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@snoopyflyingace](https://forum.inductiveautomation.com/u/snoopyflyingace)\
**Post date:** [November 3, 2017, 2:38am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/1 "2017-11-03T02:38:21Z")

</div>

Can I color the rows alternating as well as highlight a cell based on the value in it?

I was able to alternate the rows by writing the code in the initialize function or i can color the cell by writing something in the configureCell but I am not able to do both. Can anyone shed some light on how I can achieve this?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 3, 2017, 6:59am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/2 "2017-11-03T06:59:14Z")

</div>

If the colour needs to change during runtime, you will have to do everything in the configureCell function.

You can set a default colour based on the row number, and make it alternating that way (different colour for even and odd rows). And then override the colour for the cells that have the “selected” flag set.

---

<div class="post-metadata">

**Author:** ![snoopyflyingace](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@snoopyflyingace](https://forum.inductiveautomation.com/u/snoopyflyingace)\
**Post date:** [November 3, 2017, 11:56am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/3 "2017-11-03T11:56:28Z")

</div>

I tried that but it does not seem to have the effect i like.

By default i want alternating rows colored. I am able to do this by have the code in initialize function.

I also want the individual cell colored based on the value so I have the code to check the value in configureCell function; as soon as I do that the alternating row coloring is lost. Looks like I can either have the rows colored or the cell colored but not both.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 3, 2017, 11:57am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/4 "2017-11-03T11:57:19Z")

</div>

Can you share the code of the configureCell function?

---

<div class="post-metadata">

**Author:** ![snoopyflyingace](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@snoopyflyingace](https://forum.inductiveautomation.com/u/snoopyflyingace)\
**Post date:** [November 3, 2017, 11:58am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/5 "2017-11-03T11:58:12Z")

</div>

```
if selected:
	return {'background': self.selectionBackground}
elif colName == "otanks" and value > 2:
	return {'background' : 'red'}
```

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 3, 2017, 12:07pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/6 "2017-11-03T12:07:16Z")

</div>

Well, there’s no alternating colours in that code. If you want alternating colours, you should do something like this:

```auto
ret = {}
if rowIndex == self.selectedRow:
	ret["background"] = "#A0A0FF" 
elif rowIndex % 2 == 0:
	ret["background"] = "#F0F0F0"
else:
	ret["background"] = "#FFFFFF"
return ret

```

---

<div class="post-metadata">

**Author:** ![snoopyflyingace](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@snoopyflyingace](https://forum.inductiveautomation.com/u/snoopyflyingace)\
**Post date:** [November 3, 2017, 12:42pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/7 "2017-11-03T12:42:42Z")

</div>

If i did like what you suggested then I end up with only alternate row coloring. But i would like to add cell coloring in addition to that something like the attached picture

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e670577d70ca14caa7b93f2e807a15fe008c02ee.png)

---

<div class="post-metadata">

**Author:** ![Paullys50](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paullys50/32/3324_2.png) [@Paullys50](https://forum.inductiveautomation.com/u/Paullys50)\
**Post date:** [November 3, 2017, 1:44pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/8 "2017-11-03T13:44:23Z")

</div>

You need to cascade additional if/else statements. The following is pseudo code to illustrate the point

```auto
if rowIndex is odd:
    rowColor = "Grey"
    if cellHeader == "Header 2" and selectedIndex == rowIndex:
        cellColor = "Red"
    else:
        cellColor = "Grey"
else:
   rowColor = "White"
    if cellHeader == "Header 2" and selectedIndex == rowIndex:
        cellColor = "Red"
    else:
        cellColor = "White"

```

---

<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:** [November 3, 2017, 2:42pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/9 "2017-11-03T14:42:58Z")

</div>

The way I do it is to build a dictionary of attributes, starting with the formatting of least precedence. Then I add or ‘override’ attributes with additional logic as needed.

```auto
attributes = {"background": "#FFFFFF", "foreground": "#000000"}
if rowIndex % 2 == 0:
	attributes["background"] = "#EEECE8"
if colName == "val":
	if self.data.getValueAt(rowIndex, "writeable") == True:
		attributes["background"] = "#FFFF47"
if colName == "alarm" and value is not None:
	attributes["text"] = None
elif colName == "unit" and value is None:
	attributes["text"] = None
	if self.data.getValueAt(rowIndex, "alarm") is not None:
		attributes["iconPath"] = "CustomIcons/Indicator_Red.png"
		if value < 1:
			attributes["iconPath"] = "CustomIcons/Indicator_Green.png"

return attributes

```

---

<div class="post-metadata">

**Author:** ![snoopyflyingace](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@snoopyflyingace](https://forum.inductiveautomation.com/u/snoopyflyingace)\
**Post date:** [November 3, 2017, 3:32pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/10 "2017-11-03T15:32:36Z")

</div>

This is great !! Thanks a bunch. I was able to modify to get the desired result.

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [May 3, 2019, 9:12pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/11 "2019-05-03T21:12:15Z")

</div>

I am trying to highlight a complete row white, yellow or green based on a value in a column(10) in the cell. It is a number 0 to 100 where 0 would be white, 100 would be green and yellow is 0 thru 100.

Thought I could use something like this(self.data.getValueAt(rowIndex ,10)🙂 but the variations of code I could only get the column 10 to work. I don’t know how to apply the color for the whole row based on 1 column’s value of that row.

---

<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:** [May 3, 2019, 10:30pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/12 "2019-05-03T22:30:10Z")

</div>

It sounds like you are only having the script run for that column. Take out any conditional that filters on that column.

The example I posted is built to format differently for cells in each column. I you want every cell in each row to be highlighted then you don;t need to check the colName variable.

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [May 5, 2019, 3:18pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/13 "2019-05-05T15:18:12Z")

</div>

My understanding is that each cell is examined for its cell formatting. I am not sure how to apply code for each cell in a row to look at another cells value and then apply the color. Any help would be appreciated.

---

<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:** [May 6, 2019, 12:56pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/14 "2019-05-06T12:56:12Z")

</div>

That is correct; the extension function runs for each cell in the table.

My example posted above filters down to specific columns.

```auto
if colName == "val":
		if self.data.getValueAt(rowIndex, "writeable") == True:
			attributes["background"] = "#FFFF47"

```

If the cell being checked is not in that column (or one of the others in the other conditionals) then no script will be run.

If you want to run the script for all cells in a given row, simply take out the “if columnName = …” check.

Your script would be similar to this:

```auto
columnTenValue = self.data.getValueAt(rowIndex, 10) 
if columnTenValue == 0:
    return {"foreground": "#FFFFFF"}
elif columnTenValue < 100:
    return {"foreground": "#00FF00"}
return {"foreground": "#FFFF00"}

```

---

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [May 14, 2019, 8:23pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/15 "2019-05-14T20:23:37Z")

</div>

This post may help as well.

> [@Named Query, Power table, Row color based off column value](http://forum.inductiveautomation.com/t/named-query-power-table-row-color-based-off-column-value/20779):
>
> This should be fairly easy however I am quite new at this, scoured the forms and much of what I’ve found is quite vague. I have a power table running a named query that updates every 5 min. I would like to change the row colors based on the value in column 8. The values in column 8 go up to 400. From 0-90 I would like the row to be red, from 90-120 the row yellow, from 120-400 green. I have tried various scripts in the configureCell to no avail. Can this be done by binding in the Backgroun…

---

<div class="post-metadata">

**Author:** ![gmiroclosa](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gmiroclosa/32/21572_2.png) [@gmiroclosa](https://forum.inductiveautomation.com/u/gmiroclosa)\
**Post date:** [April 13, 2022, 1:55pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/16 "2022-04-13T13:55:40Z")

</div>

Hi,  
I’ve errors when I use rowIndex:  
…expecting INDENT…  
Afer so much time searching for an typping error I tried the code only changing:  
rowIndex for rowView.  
Then it works for me.

---

<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:** [April 13, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/17 "2022-04-13T15:14:46Z")

</div>

> [@gmiroclosa](#):
>
> …expecting INDENT…

That suggests a Python indentation error. Pay attention to consistent indentation and use tabs.  
If pasting code here then use the `</>` code formatting button to format your code correctly and apply syntax highlighting.

---

<div class="post-metadata">

**Author:** ![srinivas\_anupurapu](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@srinivas\_anupurapu](https://forum.inductiveautomation.com/u/srinivas_anupurapu)\
**Post date:** [June 17, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/18 "2023-06-17T18:42:22Z")

</div>

Hey snoopyflyingace,

Can you Please share your code ? , I have exact requirement  
Thank you

---

<div class="post-metadata">

**Author:** ![cbanzet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cbanzet/32/6207_2.png) [@cbanzet](https://forum.inductiveautomation.com/u/cbanzet)\
**Post date:** [June 20, 2023, 10:24pm UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/20 "2023-06-20T22:24:50Z")

</div>

@srinivas_anupurapu - You're asking in a thread that has been more than a year since the last post so it's unlikely that the original posters will notice this. I happened to stumble on to this, so I will show you an example I have done.

This configures a power table with alternating light yellow and light green rows by default. If a **cell** contains a NULL value, then that cell is gray (without changing the rest of the row). If a cell contains a date too far in the future, the cell is light blue. If the cell contains a date whose hour is set to 12 then that cell is red.

```auto
def configureCell(self, value, textValue, selected, rowIndex, colIndex, colName, rowView, colView):
	import datetime
	if colIndex > 0 and value == None:
		return {'background': '#D5D5D5'}
	try:
		if colIndex > 0 and value > datetime.datetime(2099,12,31):
			return {'foreground': '#3CCAE7',
					'background': '#3CCAE7'}
		elif colIndex > 0 and value.hours == 12:
			return {'background': '#FF6858'}
		elif selected:
			return {'background': self.selectionBackground}
		elif rowView % 2 == 0:
			return {'background': '#CCFFCC'}
		else:
			return {'background': '#FAFFCC'}
	except:
		if selected:
			return {'background': self.selectionBackground}
		elif rowView % 2 == 0:
			return {'background': '#CCFFCC'}
		else:
			return {'background': '#FAFFCC'}
		

```

Here's what it looks like...

 ![2023-06-20_152004](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f13d31f51cfaa4e49501d37c8f19b998bc53fd15.png)

---

<div class="post-metadata">

**Author:** ![srinivas\_anupurapu](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@srinivas\_anupurapu](https://forum.inductiveautomation.com/u/srinivas_anupurapu)\
**Post date:** [June 22, 2023, 8:53am UTC](https://forum.inductiveautomation.com/t/power-table-row-and-cell-coloring/15864/21 "2023-06-22T08:53:37Z")

</div>

Thank you so much for your support, modified the code as per my requirement.
