# Filter data on power table

**URL:** <https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933>\
**Category:** Ignition\
**Created:** [December 9, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933 "2023-12-09T15:38:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 9, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/1 "2023-12-09T15:38:22Z")

</div>

```auto
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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f1191a745966021d268c96aa99a6ae3acedf89a8.png)

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.

---

<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:** [December 9, 2023, 3:56pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/2 "2023-12-09T15:56:59Z")

</div>

> [@sebastien\_ng](#):
>
> `system.alarm.queryStatus`

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.)

> [@sebastien\_ng](#):
>
> is a function that I can applied/use to sort

Consider using my [orderBy()](https://www.automation-pros.com/toolkit/doc/iteration.html#orderby) expression function in a binding. From my [Integration Toolkit module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934).

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 9, 2023, 4:23pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/3 "2023-12-09T16:23:17Z")

</div>

> [@sebastien\_ng](#):
>
> I would like sort my table by `EventTime`.

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

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

```

> [@sebastien\_ng](#):
>
> I would also like the script to run in real time

I like this approach:

> [@How to get active alarm count of all tags in a folder?](https://forum.inductiveautomation.com/t/how-to-get-active-alarm-count-of-all-tags-in-a-folder/80484/7):
>
> It is safe to call from an asynchronous function, triggered from a client timer event, and writing results to a client tag. Everything else in the Vision client should reference the client tag.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 9, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/4 "2023-12-09T17:28:35Z")

</div>

> [@sebastien\_ng](#):
>
> ```auto
> table = event.source.parent.getComponent('Power Table')
> state = [0]
> results = system.alarm.queryStatus(provider="NorthTag",displaypath=["*Motor 1*"], state=state)
> table.data = results.getDataset()
> 
> ```

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 9, 2023, 5:29pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/5 "2023-12-09T17:29:11Z")

</div>

> [@justinedwards.jle](#):
>
> `table.data = system.dataset.sort(results.dataset, 'EventTime')`

thank you @justinedwards.jle

---

<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:** [December 9, 2023, 6:38pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/6 "2023-12-09T18:38:57Z")

</div>

> [@sebastien\_ng](#):
>
> this is what I did

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).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2023, 8:21pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/7 "2023-12-09T20:21:53Z")

</div>

Consider using a [Function Binding](https://docs.inductiveautomation.com/display/DOC81/Function+Bindings), 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.

---

<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:** [December 9, 2023, 8:31pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/8 "2023-12-09T20:31:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2023, 9:22pm UTC](https://forum.inductiveautomation.com/t/filter-data-on-power-table/82933/9 "2023-12-09T21:22:43Z")

</div>

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