Updating a table on another window

I have a main window which contains a table and a number of other controls. When the user selects an entry in the table the other controls are populated with associated data.

I also have a popup window I use to add a new entry and associated data into the system. When the user presses save, I would like the system to update the table on the main window and select the new entry. I am currently trying the following code: window = system.gui.getWindow('Main window') table = window.rootContainer.getComponent('Table 1') system.db.refresh(table, 'data') selectedRow = -1 for row in range(table.data.rowCount): if table.data.getValueAt(row, 0) == number: selectedRow = row break table.setSelectedRow(selectedRow) ‘number’ contains the value of the new entry.

I find that if I print the table entries this code is reading, it is apparent it is running before the table has been updated. I’ve tried putting the code in a function and calling it with system.util.invokeLater but this doesn’t seem to work either.

Any ideas how to run this code after the data in the table is updated?

The problem you’ve encountered is that system.db.refresh() is asynchronous – it returns immediately after kicking off the dataset update. The update then goes and requests the query execution from the gateway, which requires both communication and query execution time. And you don’t know how long that’ll be. While typically milliseconds, a comms hiccup or slow query could make it seconds instead.
I would address this by adding two properties to the source table: boolean ‘updating’, and number ‘selector’. Then you can put the selection logic in the table’s propertyChange event:if event.propertyName=='data': table = event.source if table.updating: table.updating = False for row in range(table.data.rowCount): if table.selector==table.data.getValueAt(row, 0): table.selectedRow = row breakThen your popup’s save event code would end with: window = system.gui.getWindow('Main window') table = window.rootContainer.getComponent('Table 1') table.selector = number table.updating = True system.db.refresh(table, 'data')

1 Like

Also, consider using the ‘updating’ property to disable the table or otherwise visually indicate that an update is on the way.

Thanks Phil, that’s working perfectly :thumb_left: Much better to put the logic on the item being updated and let it handle it when it’s ready.