# How do I customize a Power Table to change color of a row depending on PLC output

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824>\
**Category:** Ignition\
**Tags:** scripting, vision\
**Created:** [July 25, 2023, 1:28am UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824 "2023-07-25T01:28:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [July 25, 2023, 1:28am UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/1 "2023-07-25T01:28:51Z")

</div>

I have a power table with 8 rows of parts and 2 columns. A PLC is connected to an inspection camera. I want the row to be highlighted green when the correct part is picked and if an incorrect part is detected the row is highlighted with red color and the correct part that was supposed to be picked up is highlighted in yellow. Any help/pointers would be appreciated.

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [July 25, 2023, 2:27am UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/2 "2023-07-25T02:27:54Z")

</div>

Check this out.

> [@POWER TABLE background color of row](https://forum.inductiveautomation.com/t/power-table-background-color-of-row/21178):
>
> 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:** ![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:** [July 25, 2023, 4:51am UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/3 "2023-07-25T04:51:34Z")

</div>

The way your post reads, I am imagining that your first column is the expected value, and your second column is the value returned by the camera. If true, you can do the check in the following way using the configureCell extension function to get the result you are after:

```auto
#def configureCell(self, [...]):
	if self.data.getValueAt(rowIndex, 0) == self.data.getValueAt(rowIndex, 1):
		return {'background': 'green', 'foreground': 'white'}
	elif colIndex == 0:
		return {'background': 'yellow', 'foreground': 'black'}
	else:
		return {'background': 'red', 'foreground': 'white'}

```

The code simply compares the two columns in each row, and if they are the same, it sets the color to green. Otherwise, it sets the first column to yellow, and the second column to red.

**Here is the result:**

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

---

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [July 25, 2023, 6:06pm UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/4 "2023-07-25T18:06:29Z")

</div>

Sory if my original post wasn't clear enough. So, both the columns have fixed text. When the camera is triggered, it cycles through the program starting at Program 0 and stops when it finds a matching part in the program. The camera returns a pass/fail which is binded to a tag. I want to compare the program number it stopped on to the anticipated program number which would be highlighted in yellow. The anticipated program number is populated on a text field. If it matches, the name of the part is highlighted in green and if it does not the part the program stopped on is highlighted in red. I hope this made it clear.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/c/bc7f477102eb3d5a70dcfe5e713a332c8601d7a5.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 25, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/5 "2023-07-25T18:52:37Z")

</div>

I had to do something similar. I had a PLC with a step counter and wanted to highlight the specific step the PLC said it was one. I configured my colors in a configureCell extension function. I had to use a little java magic to actually make it work though. You might find the thread of value

> [@What triggers configureCell on a powertable?](https://forum.inductiveautomation.com/t/what-triggers-configurecell-on-a-powertable/63454):
>
> I have a table that lists out a sequence of steps the PLC is going through. I want to highlight the current step that is being run and to grey out the previous steps and right now I have a custom property on my table that is bound to the PLC tag that says what step it is on like this and in my configureCell I have the following script - try: curStep = self.currentSequenceStep - 1 if rowIndex \< curStep: return {'background':'grey'} elif rowIndex == curStep: return {'back…

---

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [July 27, 2023, 3:24am UTC](https://forum.inductiveautomation.com/t/how-do-i-customize-a-power-table-to-change-color-of-a-row-depending-on-plc-output/76824/6 "2023-07-27T03:24:18Z")

</div>

I ended up using the following script

```auto

attributes = {'background': 'White', 'foreground': 'Black'}
	if colName == "Seed Tube Part Number" and value == self.PartNumber:
      	  attributes['background'] = 'Blue'
      	  attributes['foreground'] = 'White'
	if colName == "Program Number" and value == self.CurrentProgramNumber and self.Pass == True:
        	attributes['background'] = 'Green'
      		attributes['foreground'] = 'white'
	if colName == "Program Number" and value == self.CurrentProgramNumber and self.Fail == True:
			attributes['background'] = 'Red'
			attributes['foreground'] = 'white'
	
	
	return attributes

```
