Set Perspective table selection from script/code

Let me start by mentioning that I searched through the forum before posting this…

I can’t figure out how to set the selected column on a Perspective table in such a way that the cell is highlighted in the same way that it would be highlighted if one would click on the table.

My table contains a single row and just a couple of columns. If I set props.selection.selectedColumn from code and check it (e.g. via a label displaying that property), I can clearly see the value is set correctly. It doesn’t matter whether the Table already has focus or not, the property change does not cause the component to redraw or display the selection. It seems only a mouse click in the cell does…

Is there ANY way I can achieve this?

If I remember correctly, that property is “read-only”, and so even if you write to it the table does not reflect the change. The property is intended to represent the selection put in place by the user - not to modify the Table via scripting.

Update: I stand corrected.

What version are you on? Are you also updating the selectedRow property to 0? That property will initialize as Null regardless of the number of rows in the table.

I tested just now, on 8.1.13, by using property bindings on the selectedColumn and selectedRow properties to input components. We can then adjust the highlighted column name and row number to change selection highlight.

image

Thanks guys, after the last post I realized I made a tiny but significant mistake. Turns out it the property selectedColumn is not read-only, but I assigned an incorrect value.

My table data has a query binding which always delivers a single row with 5 columns. The columns are named ‘1’ through ‘5’. When quickly testing with a Change Script on the data property:

self.props.selection.selectedColumn = 2 (FAILED)
self.props.selection.selectedColumn = ‘2’ (PASSED)

Duh… :slight_smile:

I was triggered by the example binding, setting ‘country’ :wink:

1 Like