Cell color in Power table with configureCell and column widths

I have a boolean column that I want to change the color of that cell based on its value (and if possible change the text) and I can’t seem to get it working. This was easy with a regular table using the Translate List and Background Color List attributes. In my power table, I tried this under configureCell:

if colName == "Pass" and value == 1:
	return {'Text': 'Pass','background': system.gui.color(0, 255, 0)}
else:
	return {'Text': 'Fail','background': system.gui.color(255, 0, 0)}

and nothing changed.

This looked like it would work, but then the whole computer started acting up and didn’t want to display anything including menus and such in Designer (endless loop?):

isChecked = self.data.getValueAt(rowIndex,"Pass")
if colName == "Pass" and isChecked:
	return {'Text': 'Pass','background': system.gui.color(0, 255, 0)}
else:
	return {'Text': 'Fail','background': system.gui.color(255, 0, 0)}

What am I doing wrong?

And what determines the scope of what gets changed - is it checking it cell by cell and the logic itself can make the whole row change?

Also, in a regular table, I can affect the size of the columns so that columns with small values are thin and other columns with long strings are wider. Is there a way to do this (at least as the starting point) in Power tables so each time they don’t have to change them?

For changing background color:

isChecked = self.data.getValueAt(rowIndex,"Pass")
if colName == "Pass" and isChecked:
       return {'Text': 'Pass','background': (0, 255, 0)}
else:
	return {'Text': 'Fail','background': (255, 0, 0)}

And yes it is formatting per cell. If you want to color the whole row, just leave out the colName check.

Column sizing is trickier. Here is a function I wrote that I use to try to size columns to fit their contents. It works well when the table data is not longer than the width of the table.

def adjust_power_table_column_size(table, ignore_columns=[]):

	# Resize the table columns to to try to make all text visible
	from com.inductiveautomation.factorypmi.application.components import VisionAdvancedTable
	
	if type(table) is VisionAdvancedTable:
	
		ds = table.viewDataset
		
		# Get list of boolean column indexes
		ds_attributes = table.columnAttributesData
		headers = system.dataset.getColumnHeaders(ds)
		
		bool_names = [ds_attributes.getValueAt(row, "Name") for row in range(ds_attributes.rowCount) if ds_attributes.getValueAt(row, "treatAsBoolean")]
		bool_cols = [headers.index(name) for name in bool_names]
		
		ignore_cols = ignore_columns + [headers.index(name) for name in ignore_columns if name in headers]
		
		g = table.getTable().getGraphics()
		if g is not None:
			lengths = {}
			frc = g.getFontRenderContext()
		
			for row in range(ds.rowCount):
				for col in range(ds.columnCount):
					if col in ignore_cols:
						continue
					elif col in bool_cols:
						lengths[col] = 5
					boundPart = table.font.getStringBounds(str(ds.getValueAt(row, col)), frc)
					if int(boundPart.getWidth()) > lengths.get(col, 0):
						lengths[col] = int(boundPart.getWidth())
		
			for col in lengths:
				table.setColumnWidth(col, lengths[col])

So, your background code like the second one I posted causes the screen to become rather unresponsive - Menus in Designer don’t want to display and the report is blank in the Ap.

That’s almost certainly a propertyChange loop, induced by writing to the column definitions dataset prop. I recommend you set up a logger in a project script, then sprinkle logger.info() calls throughout all your event routines and custom methods. Infinite loops will leave a lot of evidence in your debug console.