Select a Perspective Table Cell to Open a Parameterized Popup

First, what I am trying to do is open a popup view and pass two parameters to it when a user selects a cell in a Perspective table (enableRowSelection and enableColumnSelection are both true). I have configured a Script Action in the onSelectionChange component event to accomplish this, and it works... mostly.

One of the parameters comes from the table's props.selection.data[0], whose value I am getting on its own by adding .values()[0]; I am calling this the piece. The other parameter is a Custom property called section that looks for the piece in a different custom property (whose data is static) and returns a correlated string value.

The issue I'm having is that the section property being pulled into the onSelectionChange script action is delayed by one selection change. In other words, when I select a cell in a running session, the piece property populates with the newly selected cell value like it should, but the section property is populated with the value associated with the previous cell selection. For example, in a new page with the table, with nothing selected, when I select a cell for the first time, piece becomes piece1 like it should, but section remains null, when it should be section1. When I select a new cell, piece becomes piece2, and section becomes section1, when it should be section2. This pattern continues with all additional selections.

I considered the possibility of onSelectionChange being the wrong event for triggering the action, but onClick won't even open a popup at all, and I am getting 1 of 2 properties like I expected, so I feel like the issue lies elsewhere.

Any guidance is appreciated.
Thank you.

You are expecting bindings to occur before events. The selection changes, then both the event and the dependent bindings execute, possibly in parallel. No defined order of operations, so it is not surprising that the dependent binding is "later" than the event.

Some possible approaches to consider:

  • act upon a propertyChange on sections instead of the table selection. The downside is it might not be unique and therefore not fire when desired.

  • Compute section within the selection event instead of using a separate binding. Then it is assured to be correct for the decisions within the event.

Thanks for the quick reply Phil! That makes a lot of sense.

I'll have to look into your first suggestion to see how that works for me. Option two looks like a surefire winner though.