# Updating a table on another window

**URL:** <https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427>\
**Category:** Ignition\
**Created:** [September 3, 2015, 10:29am UTC](https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427 "2015-09-03T10:29:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 3, 2015, 10:29am UTC](https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427/1 "2015-09-03T10:29:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 3, 2015, 12:26pm UTC](https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427/2 "2015-09-03T12:26:02Z")

</div>

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
        break`Then 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')
`

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 3, 2015, 12:33pm UTC](https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427/3 "2015-09-03T12:33:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 3, 2015, 1:27pm UTC](https://forum.inductiveautomation.com/t/updating-a-table-on-another-window/10427/4 "2015-09-03T13:27:46Z")

</div>

Thanks Phil, that’s working perfectly ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:") Much better to put the logic on the item being updated and let it handle it when it’s ready.
