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

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.

Check this out.

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:

#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:

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

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

1 Like

I ended up using the following script


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