Transform rows in a table for different style - Perspective

Hi guys,

I need to change the color for the rows in a table where my part number matches with a part number in a list.

My “else” works, but the style in my “if” does not change. And it’s weird, because I print the style on the console and I see the style in the output table. However, the same code in the Transform in Bindings does not change the style.

I appreciate any help.

if self.getSibling("Checkbox").props.selected == True:
	PartNumber = '84906731SH' """self.getSibling("Label_3").props.text"""
	Table = system.db.runPrepQuery("SELECT  distinct B2.[ParentPart] FROM [BNDSYS02].[dbo].[BOM] B1 join [BNDSYS02].[dbo].[BOM] B2 on B1.ChildPart = B2.ChildPart inner join [Ignition].[dbo].[v_kanban]  on B2.ParentPart = Part where B1.ParentPart = ? and B2.SourcePlant = 03", [PartNumber])
	output_json = []	
	list = []	
	style_red = {"backgroundColor": "#FF0000"}
	style_blue = {"color": "#FFFFFF", "backgroundColor": "#0000D9", "fontWeight": "bold"}
	
	for row in range(Table.getRowCount()):
		for col in range(Table.getColumnCount()):
			list.append( str(Table.getValueAt(row,col).replace(' ','') ))
	
	for row in range(value.getRowCount()):
		row_object = {}
		row_value = {}
		row_style = {}
		for col in range(value.getColumnCount()):    
			row_value[value.getColumnName(col)] = value.getValueAt(row, col)
		   	row_object['value'] = row_value
	   		
	   		if value.getValueAt(row, col) in list:
				row_style = style_blue		     	    
		   	row_object['style'] = row_style
		output_json.append(row_object)
	return output_json
	
else: 

	output_json = []
	
	style_red = {"backgroundColor": "#FF0000"}
	style_green = {"backgroundColor": "#00AA00", "fontWeight": "bold", "fontSize": 35}
	style_yellow = {"backgroundColor": "#FFFF00"}
	
	for row in range(value.getRowCount()):
		row_object = {}
		row_value = {}
		row_style = {}
		for col in range(value.getColumnCount()):    
			row_value[value.getColumnName(col)] = value.getValueAt(row, col)
			row_object['value'] = row_value
			
			if value.getValueAt(row, col) == value.getValueAt(0, 0):
				row_style = style_green
			row_object['style'] = row_style
		output_json.append(row_object)
	return output_json


Unless the value returned from your Named Query changes you should not expect your table to update.

Also, you can replace

if self.getSibling("Checkbox").props.selected == True:

with

if self.getSibling("Checkbox").props.selected:

When I executed your script as part of a transform while in preview mode I see no change occurring when I click the checkbox because the data returned from the Named Query has not changed. If I change the state of the checkbox, exit preview mode, and examine the binding, it re-evaluates and then shows the changes.

Design mode, with checkbox unselected:

Preview mode, checkbox has become selected:

Design mode, after the binding has been examined (which triggers a re-evaluation) and OK has been clicked:


In my local environment, the third row has no matching values between my datasets, while the other three rows do have matching values.

Thank you so much!

It works now. The value returned from Named Query changes as I change the label. I also set the polling from table to every 1 sec. It’s updating as it should.