Configure Individual Cell Color based on Value (Vision Power Table)

Hello everyone,

Id like to see if its possible to change the row color of a table based on a value in the row. As of right now i have done some tests, but cant seem to figure out how to do it correctly or assign an individual row a color.

I want to color the row red in case the column value at a certain index is None, and for the others i want to color them green.

This is the code im using in the configureCell extended function of a power table:

tabla = self.data
	for row in range(tabla.getRowCount()):
		valor_revisado = tabla.getValueAt(row, 'Revisado_Por')
		#print valor_revisado
		if None in valor_revisado:
			return {'background': 'red'}
		else:
			return {'background': 'green'}

The problem is this code just colors the whole table.

I was hoping i could get some assistance from you guys.

Thanks.

Daniel

Hi Daniel, is that code as-is from your ‘configureCell’ function?

That function is called once per cell in a table, and it seems you’re looping from the first row in every call.

Try removing the for loop and use the rowIndex parameter instead. Eg. self.data.getValueAt(rowIndex, 'Revisado_Por')

Yes, the solution actually worked. I didnt know it run once per cell in a table.

The code in the end is the following:

valor_revisado = self.data.getValueAt(rowIndex, 'Revisado_Por')
		#print valor_revisado
	if valor_revisado != None:
		return {'background': 'white'}
	else: 
		return {'background': 'red'}

Thank you so much for your help and comment @gdube