Perspective Table Binding after Popup Close

So, I have a table that shows me the results of a named query. When I double click a row, it opens a popup and allows me to edit fields relevant to the record I clicked on. That works fine.

After closing the popup, how do I fire an event to refresh the binding on the table?

I did have an onFocus event on the root container with:
self.getChild(“Current Users Table”).refreshBinding(“props.data”)

I could have sworn this was working perfectly at one point, but now it isn’t… Anyway, anybody have any ideas?

Thanks in advance!

Closing the Popup is not necessarily enough to force focus onto the root container.

Your refreshBinding usage looks correct, so I would double-check that clicking somewhere in the root container results in the data refresh. If you don’t see it happen, check your Gateway logs to verify your table is a direct child of the root container and that your problem is not the result of a reference path issue.

Clicking on the table (or even clicking another table on the same view) indeed refreshes the binding.

The desired action though would be that no clicking is required though, is there any way around it?

Maybe if instead of just closing the popup, I instead use navigation to go back to the view containing the table, which would reload it?

Yes, but it will require use of Message Handling.

What I recommend in cases like this is dependent on the requirements of the Popup. If the Popup manipulates data in any way, then you should opt to not use the “close icon” (the x in the upper right) and should instead use your own button to close the Popup, This is more in-line with contemporary expectations revolving around a user committing or confirming their changes as opposed to dismissing a popup. The use of a Button allows you to hook into the process, so instead of just closing the Popup you can also place your own code within a script action where you invoke sendMessage() before then closing the popup. If your Popup requires the close icon for some reason, you’ll need to use the Message Handler as part of the View onShutdown Event for the View you are using in the Popup.

Message handler invocation:

system.perspective.sendMessage('update_table', scope='page')
system.perspective.closePopup('YourPopupIdHere')

The Table needs to have a listener set up for the message handler you just created. Right-click the Table and select “Configure Scripts”. Add a new handler where the name is “update_table”, set the scope to be “page” and supply the following code:

self.refreshBinding('props.data')
2 Likes

That worked perfectly, thanks!

I hadn’t used sendMessage or handlers before, I’ll have to read up on it I suppose.

1 Like

Message Handlers are an amazing resource for communicating in Perspective. The scope of property references (bindings and script usages) is limited to the scope of the View, and is inherently fragile, because any nesting of components at some later time will break the path you’ve defined and result in faulted references.

While Message Handling has some additional overhead when setting up it is incredibly resilient, only prone to breaking if you manage the scope incorrectly, or if you specify the wrong name. Some users encounter issues when they modify the params supplied during the invocation, but that’s a fault of their own code and not the handler itself.

I absolutely recommend reading up on message handlers and using them when you need to communicate between Views, whether they are popups, docked views, or even different pages within a session.