Filter data on power table

table = event.source.parent.getComponent('Power Table')
state = [0]
results = system.alarm.queryStatus(provider="NorthTag",displaypath=["*Motor 1*"], state=state)
table.data = results.getDataset()

THis what I'am getting.

image

I would like sort my table by EventTime.

My questions is :
There is a function that I can applied/use to sort EventTime column ?
note:The script above I put it on a button. when I click on a button, I can see data on this table.
but I would also like the script to run in real time instead of using a button.

You are running this very heavyweight function in a UI event routine. Expect client UI freezes.

Use an asynchronous thread to run this, and post the results back to the UI with invokeLater(). (Lots of discussions here on these techniques. Use them before you suffer for it.)

Consider using my orderBy() expression function in a binding. From my Integration Toolkit module.

1 Like

If you want to get the data sorted using a script, you can get it this way:

table.data = system.dataset.sort(results.dataset, 'EventTime')

I like this approach:

2 Likes

Hello @pturmel thank you ,
this is what I did:

def getAlarm():
	import system
	table = event.source.parent.getComponent('Power Table')
	state = [0]
	results = system.alarm.queryStatus(provider="NorthTag",displaypath=["*Motor 1*"], state=state)
	table.data = results.getDataset()
	
system.util.invokeLater(getAlarm, 1000)

thank you @justinedwards.jle

Well, no, that isn't a background (asynchronous) thread. invokeLater() runs the given function on the foreground thread--the same thread as the UI. You need system.util.invokeAsynchronous() to run in the background. The assignment to table.data is the part that needs to be on the foreground (because it operates on a GUI component--Swing requires that be in the foreground).

1 Like

Consider using a Function Binding, instead of needing to do anything with scripting. You could bring the raw query dataset in on one custom property and use an expression function to sort the results for an efficient, easy to configure option.

4 Likes

BTW, your advice suggests that function bindings run asynchronously. I looked at using this extension point for some DB cache functionality, but couldn't tell if that were true. Hmmm?

2 Likes

Yes, they're automatically run async through the QueryExecuter [sic] explicitly bound thread pool, with a default 7 threads.

4 Likes