Trigger binding AFTER other bindings


Using Perspective 8.1.14.

Is there any way to trigger a binding AFTER several other bindings on the page?

I have a single binding that does some slightly complex calculations on the inputs, then runs a generated query in a transform and displays the output in a table.

The inputs to the query come from many input components (mostly dropdowns) on the page which themselves are initialized via bindings.

However, at page load, as each binding on the input components is executed, it triggers the binding which generates the query and updates the table, so the query and table gets updated potentially many times. (It seems to be quite random the binding trigger order).

I would like the generated query and table update to execute last on page load so that the table is only initialized once on page load, and then updated when any of the input components change.

Is there anyway to accomplish this? or some other way to go about this?


Good question! According to answers in these two posts it’s not possible.

I’m surprise that the binding’s Enabled property isn’t available in script.

A possible work around is to put an IF statement into your query’s WHERE statement and pass in the query “enabled” as a QueryString variable. In MySQL it looks like this:

SELECT <field1>, etc.
FROM <tablename>
WHERE IF({enabled} = '1', id > 0, id < 0)

I tested this by binding to a toggle switch with this binding:
if({../ToggleSwitch.props.selected}, '1', '0')

In your case you might need to create a property on something with an expression that somehow detects that the dropdowns have been populated.

The binding will probably run once on view load but should be quick if you use a primary key in the IF statement. It will then execute again when the {enabled} querystring turns on.

I did something like this once by having custom properties monitor the loading state of several components.
All my bindings went through a script transform, so I added just one line before returning, that looked like this:

self.view.custom.component_x_loaded = True

And then I had one more property that I called view_loaded and that was bound to all the component_x_loaded.
Then anything that needed to wait for other components to load checked if view_loaded was true before doing any calculation.

Now that was several versions ago, so there might be better mechanisms in place now. But it works.

What if you use an Expression Structure binding and set it to “Wait on All”?


Using an Expression Structure and “Wait on All” helped significantly, and reduced the number of times the query is triggered on “page load” to two. Still trying to figure that out, but it is much better. It was firing up to 7-8 times previously.

Do Perspective components have that property?

It’s under the ‘custom’ section, meaning it’s user added/provided.

I spoke to soon. More testing with the Expression Structure approach still seems to trigger the query table update quite often. I’ll try to post an example view demonstrating this.

With Embedded Views you can set them to load after the parent view.
If you put your table on that view, I’m pretty sure it would load last, after all the other bindings. All your info would have to be passed as parameters though, so it might be much.