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.

2 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