Best way to update a table that was created dynamically from an event script

Hi Everyone,

I'm struggling with the best way to program the functionality I'm looking for here.

Using perspective, I have a Dropdown component, that gets it's data from a SQL database. The list is a list of Equipment Groups.

When the user selects an Equipment Group from the list, the onActionPerformed event fires, and I run a script that takes a look at all the HOA tags I have under the folder of that name that matches the value prop of the dropdown. All good so far.

In the same script, I then dynamically build a list of tags and stuff it into a table using the data prop. Again all works beautifully.

Now the user can select a row, and that will let me call a popup for that particular tag and change the state of the HOA. Still working great.

Now what I want to happen, is when I close that popup, I want the underlying data on the table to update. Since the actual table data did not actually change (because its a static list I built dynamically) there's no way to just refresh it. I have explored various ways of trying to get the dropdown to reactivate but none work and it seems "unclean".

I'm sure there's a good way to do this. I know I'm close and I'm just not thinking of something. Anybody have a better way of doing what I'm doing?

Thanks in advance!

Put the script from on 'OnActionPerformed' event into your project's script library. Then call it from the 'onActionPerformed' (passing the required data from whatever properties).

You can then re-use this script call in a messageHandler, either on the table or the root container of the view. Send a message via system.perspective.sendMessage() right before closing the popup to trigger the rebuild.

As an added bonus this will make your action performed and message handler scripts much smaller/cleaner.

If you ever run into the case of 'I want the logic from button x to also be able to be triggered from button/component y`, put the main logic into a project library script and then call it from the respective locations.

2 Likes

Ah ha! Yes thank you Ryan that sounds like the piece I'm missing.

Currently on the last line, my scrip stuffs the dataset right into the table self.getSibling('mytable').props.data = tableData

I assume this isn't going to work like written so do I need a different way to stuff the data into the table right from the script OR would I pass the dataset back to the calling code and have it stuff the data?

Do this

Ryan - Just wanted to return and say thanks. This worked perfectly. Took me a little to fiddle with the right syntax to pass the data set back over but once I figured that out this worked exactly as I needed. Thanks much!

1 Like