# POWER TABLE background color of row

**URL:** <https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [December 1, 2018, 10:40am UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178 "2018-12-01T10:40:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.inductiveautomation.com/u/claudio)\
**Post date:** [December 1, 2018, 10:40am UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/1 "2018-12-01T10:40:18Z")

</div>

Hello to everybody,  
I need help to set the background colour of rows of a power table object, based on the value of a specified coloumn.  
I.e. if the value of the second coloumn of my power table is 1 I need to set the background colour of that row red, if the value is 10 the corrispondent row shoud be green.

Thank you in advance  
Best regards  
Claudio

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 1, 2018, 12:58pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/2 "2018-12-01T12:58:26Z")

</div>

> [@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/2):
>
> To do that you would use the component scripting for the power table. The extension function configureCell. You would want to check for the value using something like: val = self.data.getValueAt(rowIndex,"column title") if val \>= 0 and val \<=90: return{'background': 'red'} if val \>= 91 and val \<=120 : return{'background': 'yellow'}

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 11, 2021, 7:20pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/3 "2021-10-11T19:20:18Z")

</div>

This is correct for a static table. How do you get the extension function to fire again after sorting?

---

<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:** [October 11, 2021, 7:56pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/4 "2021-10-11T19:56:37Z")

</div>

configureCell fires when the table is redrawn for the cells that need to be displayed. See this related discussion:

> [@Bug Report: Power Table configureCell()](https://forum.inductiveautomation.com/t/bug-report-power-table-configurecell/51315):
>
> There’s a bug in the configureCell() extension function on the Power Table component in Vision. I tested on 8.1 and 7.9, both of which have the bug. When selecting a row from a power table, configureCell() does not execute for all cells. Instead, the cells it executes on depend on the index of the selected row. There appears to be a logical bug in how the cells are looped over. To reproduce the bug: Create a Power Table and populate it with 5 values in one column of data. The bug is present…

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 12, 2021, 2:43pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/5 "2021-10-12T14:43:51Z")

</div>

So, why then when I use the above solution for coloring the rows based on a cell value, do the colors not follow the correct rows when the table is sorted?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 12, 2021, 3:37pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/6 "2021-10-12T15:37:20Z")

</div>

Without seeing what you have done, it’s difficult to say.

That said, one thing may be to ensure you have a default config for your cell. For example:

```python
value = self.data.getValueAt(rowIndex,"columnName"))

if value >= 0 and value <= 90 :
	return{'background': '#FF0100'}
if value >= 91 and value <=120 :
	return{'background': 'yellow'}
return{'background': 'green'} # default config

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2021, 3:43pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/7 "2021-10-12T15:43:24Z")

</div>

Also, note that there are two different row indices you get in `configureCell`- `rowIndex` and `rowView`; your code may be using the wrong index or retrieving values from the ‘wrong’ dataset (`viewDataset` vs `data`).

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 12, 2021, 9:20pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/8 "2021-10-12T21:20:07Z")

</div>

This was the issue. Thank you.

However, I don’t quite understand why rowIndex is the correct argument instead of rowView. The docstring for rowView says “(affected by sorting)” which leads me to believe that I should be using rowView.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2021, 9:53pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/9 "2021-10-12T21:53:02Z")

</div>

It depends on what you’re doing. If you’re retrieving values from the `viewDataset` property of the table, you should be using `rowView`. If you’re retrieving values from the `data` property, you should be using `rowIndex`.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [October 16, 2021, 2:17pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/10 "2021-10-16T14:17:26Z")

</div>

This worked for me

```auto
# reference column name Status
	if colName == "Status" and value == "Maint Required":
		returnValue ["background"] = "FF4747"
	elif colName == "Status" and value == "Getting Moisture":
				returnValue ["background"] = "FF4747"
	elif colName=="Status" and value == "OK":
				returnValue ["background"] = "8AFF8A"
	elif data.getValueAt(rowIndex,"EquipmentID" )==0:
				returnValue["background"] = "9ACCEE"

```

---

<div class="post-metadata">

**Author:** ![gregory.sachs](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@gregory.sachs](https://forum.inductiveautomation.com/u/gregory.sachs)\
**Post date:** [January 10, 2022, 9:04pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/11 "2022-01-10T21:04:09Z")

</div>

Another tweak, just in case someone else wants to do this:  
This will highlight the full row where the value in column x in the backing dataset changes vs the row above.  
Currently sets even rows to yellow and odd to orange.

```auto
Column_I_Want_to_Monitor = 5
	#Defines what column will be configured
	#if colIndex == Column_I_Want_to_Monitor and rowIndex > 0:
	if rowIndex > 0:
	 #Checks if the column is the right one and that it's not the first row
	 	#previousCellValue = self.data.getValueAt(rowIndex-1,colIndex)
	 	previousCellValue = self.data.getValueAt(rowIndex-1,Column_I_Want_to_Monitor)
	 	currentRowValue=self.data.getValueAt(rowIndex,Column_I_Want_to_Monitor)
	 #On the Power Chart's dataset, finds the value at the previous cell
	 	#if previousCellValue != textValue:
	 	if previousCellValue != currentRowValue:
	 		if rowIndex % 2 ==0:
	 			return {'background': 'yellow'}
	 		else:
	 			return {'background': 'orange'}

```

---

<div class="post-metadata">

**Author:** ![Gustavo\_Cardoso](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gustavo_cardoso/32/85783_2.png) [@Gustavo\_Cardoso](https://forum.inductiveautomation.com/u/Gustavo_Cardoso)\
**Post date:** [August 15, 2024, 12:31pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/12 "2024-08-15T12:31:21Z")

</div>

Hi! How are you?

I still don't understanding why rowView is not affected by sorting when retrieving values from data property... Also, the rowIndex is affected by sorting too but the only difference is it's not written in its description?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 15, 2024, 12:48pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/13 "2024-08-15T12:48:27Z")

</div>

> [@Gustavo\_Cardoso](#):
>
> why rowView is not affected by sorting [...] rowIndex is affected

The rowIndex is the position of the row as it exists in the table's dataset property. The rowView is the position of the row as it is observed by the user in the table itself.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 15, 2024, 2:04pm UTC](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178/14 "2024-08-15T14:04:20Z")

</div>

> **[How to Use Tables (The Java™ Tutorials \>        
            Creating a...](https://docs.oracle.com/javase%2Ftutorial%2F/uiswing/components/table.html#sorting)**
>
> This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components
