How to trigger SQL Query on request?

Hi there,

I have a table that gets data from SQL query. But instead of polling evey X second, I want to run the query on reqest. Like when page is loaded, and when i add data using the form below the table. How can this be accieved? Thanks :slight_smile:

Any other tips and tricks for how to make this user friendly is vey appreciated.

Screen shot of table and how users can add/update data.

The standard procedure is:

  • Create the SQL binding on the table's data property.
  • On load the binding will be automatically refreshed and the table will update.
  • Your Oppdater button will insert or update the database by script - probably using an onActionPerformed1 event.
  • At the end of the script you should use a message handler.
    system.perspective.sendMessage("updateTableDatasource", payload = {}, scope = "view")
  • On the Table component, right-click | Configure Scripts | Message Handlers | + Add Handler. Set up as shown below.

self.refreshBinding('props.data')


1 onClick will be triggered even if the button is not enabled.
onActionPerformed event will not occur if the button is not enabled.

Nice elegant form design! :clap:

1 Like

Thank you so much! That worked so damn smooth :slight_smile:

2 Likes

Hi, I just ran into another problem regarding this. I wanted to display a popup in order to confirm before deleting from the table, so I made this little popup:
image

When pressing "Ja", this script is run:

def runAction(self, event):

	parameters  = {
	"DeleteID":self.custom.key}
		
	system.db.runNamedQuery("Todo/Todo_Delete", parameters)
	system.perspective.closePopup("CTILi51V")
	system.perspective.sendMessage("refresh_todo", payload = {}, scope = "view")
	

The script delete the row, and closes the popup, but wont refresh the table. Any ideas? :slight_smile: This "refresh_todo" works when its not used in a popup, so I guess something needs to be done in order to pass it to the table or something...

Hmm..., should any parameters be passed to the message handler on the table?

Yes, I tried, and problem is the same :confused:

A popup is its own view, so scope="view" certainly won't work. Use page scope.

Thats it! Thank you :slight_smile:

Yes, and I messed up on the earlier post. The parameters were to go to the named query, not the sendMessage. I'll delete that post.

I'm glad you got it working.

1 Like