Highlight Table Row

I am sure I am just missing how this works but I cannot for whatever reason figure out how to highlight rows in a table. I am using a Table component in a Vision window, this table contains data from a Named Query and I need to be able to highlight all the rows within the table when a specific column (say col4) contains the name of the currently logged in user. I know I could accomplish this using the Table Customizer and Background Color Mapping if the column was a numeric value, however it is text.

are you opposed to using a Power Table?

It will allow you to do this via it’s configureCell extension function.

image

You would just need to modify the code in configureCell to meet your criteria

A Power Table should work too, I’ll give it a try and update.

Im not sure if I am missing something but it seems as though this should work? I just need the row to change background colors when the logged in user matches a name on the table.

if colName == "username" and value == system.client.user.username:
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

This doesn't exist. Try system.security.getUsername().

2 Likes

That doesnt quite seem to work either but I do see my mistake with using system.client.user.username. This is the updated code however it still rejects it, underlining the first return as outside function. I feel as though I am missing something in order to make this work properly or that there is an easier way to accomplish this.

userName = system.security.getUsername()
user = system.user.getUser("", userName)

if colName == 'username' and value == user.get('firstname'):
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

Why are you using system.user.getUser()? Just compare to their actual user name.

If you absolutely have to compare to their given name, compute it outside this extension function and place it in a string custom property. Then the often-called configureCell only has to compare to the custom property.

This should work to highlight the entire row where the username matches the logged in user:

if self.data.getValueAt(rowIndex, 'username') == system.security.getUsername():
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

image

2 Likes

Is your binding on the component scripting configureCell? Where you right click the Power Table and choose Scripting?

I am not sure what I am doing differently than you have.

highlight lines 34-37 and press tab one time and it should work

1 Like

Wow okay did not know that tab there mattered. Thank you!

Yep, they’re all underneath the method definition at the top! so they need to be tabbed over one time

Never even noticed that up there, I’ll keep that tab spacing in mind for future scripting!

The indentation is necessary for extension functions and custom methods and most scripts in Perspective. Events that do not show def at the top should not be indented.

2 Likes