POWER TABLE background color of row

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


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

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

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?

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:

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

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).

1 Like

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.

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.


This worked for me

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

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.

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)
	 #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'}
	 			return {'background': 'orange'}