Vision Table Row Color

Hello all,

I am trying to change the row color of my vision table based on the value of the individual cells in my table. So for example, if orderno is equal to my tag value I want that row to change the color.

image

I wrote a cellEdited script on my table and I think this should work but it does not:

attributes = {"background": "#FFFFFF"}
data=event.source.data
if data.getValueAt(colIndex, 'orderno') == system.tag.read("[System]Client/orderno"):
	attributes["background"] ="#EEECE8"

The cellEdited event has nothing to do with display. You need to perform this check in configureCell.

1 Like

You are correct! I totally forgot about that. However, I do not have the configure cell option here:

image

Probably I should switch to a power table. The code is not working in power table either

Take a close look at the event header. Extension functions and custom methods supply self and some parameters, not event. So, no event.source.

1 Like

You are correct, Phil. Thank you so much for your help. Sometimes I completely forget about these differences.

Consider doing as much as possible in project scripts, where you pass components and parameters to project functions. Either kind of event then becomes a one-liner (of different flavors) and you can maintain a single paradigm in the script library.

1 Like

I agree with you! Sometimes it is really difficult to maintain correct syntaxes as Ignition use multiple languages and sometimes it gets confusing.

I have tried different scripts but none of them worked. This script should work but it does not. It always returns the color ‘yellow’ even though orderno is equal to my ordeno tag value.

	data = self.data.getValueAt(rowIndex,"orderno")
	if data == system.tag.readBlocking("[System]Client/orderno"):
		return{'background': 'red'}
	else: 
		return{'background': 'yellow'} 

Under no circumstances should you ever do a tag read in a display-driven event. Bind that tag to custom property and use that in your event.

You can use a diagnostic print to show both values in the event.

1 Like

Thank you so much, Phil. It is working now. Appreciate your help.
This is the final code:

	if self.orderno == self.data.getValueAt(rowIndex, "orderno"):
		return {'background': 'red'}
	else:
		return {'background': 'yellow'}