Power table row selection background conflict

I have a power table which i want to be able to select a row, and then do various actions with buttons on the selected row. I want to highlight the selected row with the default selection colors Ignition implements.

However I also want to highlight a row based on some other condition, for example if a BOOL value in that row is high.
I wrote the following code in the “configureCell” extension function of the Power Table:

	testDue = self.data.getValueAt(rowIndex, "TaskDue")
	if testDue:
		return {'background': '#8AFF8A'}
	else:
		return {'background': 'white'}
	# end if

This highlights the desired rows green.

My problem is, i can no longer get the Selected Row highlight to work. I assumed that because there are different properties for “selectedBackground” and “background” that they would remain separate. But there is some conflict here.

Is it possible to do what i am trying?

Thanks a bunch.

You need to capture it in your script.

Conveniently, there’s a “selected” parameter for every cell given as function argument, so you can just use that to color it.

testDue = self.data.getValueAt(rowIndex, "TaskDue")
if selected:
	return {'background': 'orange'}
elif testDue:
	return {'background': '#8AFF8A'}
else:
	return {'background': 'white'}

What I did in the past was working with the HSL color space. With HSL, you can assign a hue to a certain state, and then change the saturation and lightness for the selected row. That way, the colors remain consistent and users still see which rows are selected.

You can find quite a few HSL to RGB and back conversion algorithms on the net. Just watch out of the bounds (values from 0 to 1, from 0 to 255, from 0 to 360, …).

2 Likes

Ah brilliant. Got a bit mixed up with what i thought was “Cell” selected and the entire “Row” being selected. But I guess if a row has been selected, then each cell in that row is configured individually as specified in the script.

The HSL idea sounds nice. I’ll look into that as well.

Thanks!

Thank you so much! So the if selected must cover the testDue part, correct?

What do you mean exactly? The code posted above has worked for me as intended.
I am actually using the code below in production now, adding an additional color for if the task is “overdue”.

	# Define initial dictionary to return
	formatDict = {'background': 'white'}
	
	# If test is due, format cell to make it stand out. 
	testDue = self.data.getValueAt(rowIndex, "TaskDue")
	testOverdue = self.data.getValueAt(rowIndex, "TaskOverdue")
	if selected:
		formatDict['background']= self.selectionBackground
	elif testOverdue:
		formatDict['background']= 'F57E59'
	elif testDue:
		formatDict['background']= 'F5CD64'
	else:
		formatDict['background']= 'white'
	# end if
	
	return formatDict
1 Like

Thank you sir!