Detecting selection changes in Vision table allowing multiselection

I want to detect when the currently selected row(s) change in a Vision table, configured to allow multiple row selection. Binding a script to the “propertychange” event, I see that a “selectedRow” event is generated only when the lowest selected row index changes, which rules out the majority of changes the user may make in the selection. Since there’s no “selectedRows” property, I need to 1) somehow detect when the selection has changed and then 2) invoke getSelectedRow() on the table to see which rows are currently selected…
My trouble is that there doesn’t seem to be a way to do 1) reliably (ie, for every change). Any advice?

Consider using a Power Table instead, using the selectedRows property (Not to be confused with selectedRow)

Does it have it? I don’t see it documented in https://docs.inductiveautomation.com/display/DOC80/Vision+-+Power+Table, neither does it show in the component’s properties pane.

Well, yeah, as I checked it out before posting. :man_shrugging:

This snippet is from the link you posted;
image

That’s not a property.

Right. But you can use this to achieve what you described in your first post.
You could also make use of the extension function onMouseClick which would fire everytime you click on a row. Try adding this in the onMouseClick and see if you can achieve what you want:

print self.getSelectedRows()

That works, although is not optimal (though of course still better than nothing), because any code you put there you would also have to put in the keyboard event handler, since selection can be changed with keyboard as well. That’s why I was looking for a central notification mechanism that would tell me “selection has changed”, regardless of how user did it.
Thanks

A simple solution to that would be to create your own method and point all the event handlers or extension functions to it. Your code would reside in 1 place.

1 Like

In the propertyChanged event handler:

if event.propertyName == 'selectedRows':
    do_some_stuff

This vid shows the properties fired.

3 Likes

Yes, that’s cool thanks. In this specific case the tables in question have lots of additional config and scripting attached, so replacng them with power tables would probably be a lot of work, so for this time I’ll go with the other solution. However for new tables I’d certainly use your method. Thanks