Skip to end of metadata
Go to start of metadata

 

Refreshing a Query

The SQL query that populates a property on a component will refresh its data periodically if the Polling Mode is set to either Relative or Absolute. However, there are times when you want the data to query the database once when the window is opened, and then retain explicit control over each subsequent refresh. The Table data can be requeried using system.db.refresh. There are two main ways of doing this: either placing the script on a button, or at the end of some code.

Refresh After Edits

If edits are being made to the Table data, or additional rows are being added, it can be a good idea to call the system.db.refresh() function after manipulating data. This way, the data in the Table will automatically refresh with the newly entered data, saving the user the hassle of clicking a refresh button.

Pseudocode - Refreshing a Table after an Edit
doWork()

system.db.runPrepUpdate("INSERT INTO table")

system.db.refresh(component, "propertyName")

On this page ...


IULocgo


Refreshing SQL Data on Component

Refresh on a Button

We can use a Button component with a script on it to refresh the component with the query binding on it. Typically the button is placed close by the query bound component, and will say something like "Refresh Data". The script is actually fairly simple, and can be placed on the actionPerformed event of the Button.

  1. Drag a Button component onto a window that has a Power Table or Table component querying a Database table.
    1. Change the Button's Text property to say "Refresh."

  2. On the Power Table component, open the data property binding and set the polling mode to off.

  3. Right click on the Button and select Scripting.
    1. Select the actionPerformed Event Handler and navigate to the Script Editor tab.
    2. Add in this script, which will force the Table's data property to refresh.

      Python - Refreshing the Database when the Button is Pressed
      # Will force the Power Table's Data property to run the query again.
      system.db.refresh(event.source.parent.getComponent('Power Table'), "data")
  4. Try it out by adding new data to the Database table and then clicking the Refresh Button.


 

  • No labels