Deselect and Un-Highlight Table Row

Issue: Perspective table row remains highlighted after selectedRow property is set to None.
Goal: Using script, deselect and un-highlight the row of a table component.

More info: I am attempting to deselect the row of the table component. I have successfully deselected the row using ...props.selection.selectedRow = None. Yet the row remains highlighted. Any suggestions to un-highlight the row would be greatly appreciated.

Note: The table that I am working with has two columns, but only one is shown.

Images:
image

1 Like

You have to set both selectedRow and selectedColumn to None.

Thank you for the response. Unfortunately I have already attempted setting both selectedRow and selectedColumn to None and it did not solve my issue.

I was able to find a work around. If the selectedRow and selectedColumn are set to -1, the row is unhighlighted. Then the selectedRow and selectedColumn can be set to None.

self.props.selection.selectedRow = -1
self.props.selection.selectedColumn = -1
self.props.selection.selectedRow = None
self.props.selection.selectedColumn = None
8 Likes

Thanks, FYI to others, do not also do selection.data = [] as it will cause the whole thing to not work.

The most reliable way I've found to do this is to disable row selection, let that bounce over to the browser, which will then clear props.selection.data. A change event on props.selection.data can then re-enable row selection when it sees the new empty value.

In general, properties that are set via user interaction in the browser, like selections, need to also be unset by the browser. Unsetting them directly via script (which runs in the gateway, not the browser) is unreliable.

5 Likes

I've been using a library function I created for this purpose. I could be mistaken but I think @pturmel has indicated that Timers aren't totally reliable, but they've always seemed to work well for my purposes.

from threading import Timer

def reenableSelect(table):
	table.props.selection.enableRowSelection = True 
		
def deselectRow(table):
	table.props.selection.selectedRow = None
	table.props.selection.enableRowSelection = False
	Timer(0.2, reenableSelect, [table]).start()

No need for a timer if you follow my pseudocode. And a timer doesn't ensure that the traffic made the round trip to the browser. (Do note that you should not blindly disable row selection--only do so when there is a non-empty selection that you wish to eliminate.)

1 Like

Hi Phil

I'm trying to do this deselect a row thing.
Are you putting this on a row-click event or on a 'clear selection' button?
If it's on the row-click (which I'd prefer, so that's what I'm attempting), what are you using as parameters to trigger disabling row selection such that it only happens if the row is currently highlighted?

Either separate button or row ctrl-click.

For both cases, only disable row selection if there is a currently selected row. Otherwise do nothing.

1 Like

Here's how I do a button to de-select row(s):

  • Button with script onActionPerformed:
    self.[relPathToTable].props.selection.enableRowSelection = False
    Button.enabled has expression binding !isNull({[relPathToTable].props.selection.selectedRow})

  • Table.selection.selectedRow has a change script.
    if currentValue.value is None:
    self.props.selection.enableRowSelection = True

Button disables row selection. This nulls table.data.selectedRow. Upon that, change script re-enables table.selection.enableRowSelection so rows can be selected again.

Wonky in how it works, but clean user experience. Thanks to @pturmel for this tip.

4 Likes