How to change cell color in message handler

Hello All,

I am trying to change the color of a specific cell (process_value) based on the value of two columns (low limit, high limit). I have the script below in the message handler. However, with this script the whole table change its color to green/red (defined color style). How should I change this to be able to change the desired cell color and not the whole table color? Thank you!

	specLL = pds.getValueAt(row,"low_limit")
	specHL = pds.getValueAt(row,"high_limit")

	if value != "":
		# Spec value is a float Process Value
		if col == "process_value":
			value = float(value)
			pds = system.dataset.setValue(pds, row,col,value)
			
			# evaluate the result
			if value <= specHL and value >= specLL:
				self.props.cells.style.classes="CellColor/green"
			else:
				self.props.cells.style.classes="CellColor/red"
	
		# UPDATE DATASET
		self.view.custom.part.spec.data = pds

I guess my question then would be how to apply color to this cell?

pds.getValueAt(row,col)

Because you’re setting the very general-scoped cells styling, which is used as the “default” for any cells which don’t have their own style attributes defined in props.data. You need to set the style for just one cell of data in props.data by modifying the style attribute of some “cell”. I’ve assisted with that ina. neighboring thread: Change style of cell (component Table) via script - Perspective - #13 by cmallonee

You shouldn’t be handling the logic like this.

What I recommend is you place all of the display logic into the table. If you need to update a value in the dataset, feel free to do so wherever, but let the Table itself resolve the binding and apply the display logic based on the new values.

2 Likes