Power Table Sort Script

For those of you who would like to know how to trigger a Power Table to sort via script, here is how you do it:

table = event.source.parent.getComponent(‘Table’)
gTable = table.getTable()
gTable.getRowSorter().toggleSortOrder(0) # the 0 (zero) sets which column to sort on


When I did something like this to turn off the filters, I found I had a memory leak. Not sure if this will apply to the sorter as well but you might need to deallocate the sorter at the end with something like;

Spent some time on this today and figured out another way to sort the Power table.
Currently running this script on Power Table “init” extension function.

from javax.swing import SortOrder
from javax.swing import RowSorter

sortList = []
sortList.append(RowSorter.SortKey(0, SortOrder.DESCENDING)) #0 equals the column number, SortOrder either "ASCENDING" or "DESCENDING".
table = self
gTable = table.getTable()
1 Like

table = self
gTable = table.getTable()
gTable.getRowSorter().toggleSortOrder(0) # the 0 (zero) sets which column to sort on

I added ‘‘Self’’ in the first line and works as a charm!


Anyone know how to apply setRowFilter to a power table?

I tried both your sample code and it works fine…
Until you have custom formating in “configureCell” event.

The event “configureCell” is not triggered after applying the sort that way.
Anybody have a solution to force the trigger of “configureCell” event ?

I just load the data in a different, custom property. Sort the dataset with a script, and put it on the table.

I also did that in the end.

I liked the way the other option was showing which column was sorted, which I do not get with the current solution.
I tried to implement both but it is not working very well.

Are you doing something like this? I’m trying to sort by script and am testing with a ‘mouse pressed’ event handler script.

unsortedData = event.source.data
sortedData = system.dataset.sort(unsortedData, 1, False)
event.source.data = sortedData

It’s not working…the table doesn’t change.

Much appreciated,

I solved the problem, perhaps not but I got it to do what I want. I had bound my client dataset tag to the table and got to thinking…if I get the from the table and sort it and set the data in the table to the new dataset created from the sorting, it probably goes into the table but is overwritten the to tag dataset because of the binding. I removed the dataset tag binding from the table then added a window-open script that reads the dataset from the tag, creates a new data set via sorting that set the table data to the sorted dataset. Bingo Gingo, it shows my sorted data.

table = system.gui.getParentWindow(event).getComponentForPath(‘mwVersionInfo.Power Table’)
readList = system.tag.readBlocking(’[gw1]_Project Version Information/versionDataSet’)
unsortedData = readList[0].value
sortedData = system.dataset.sort(unsortedData, 0, False)
table.data = sortedData

It is easier and more reliable to just add a custom dataset property to your table with the original binding. A propertyChange event that notes the change to that property would then sort and write to .data.

@pturmel Hello Phil.

I tried that; added a custom dataset property to the table and bound it to the tag with the dataset and added a project change event to the table to sort the data set.

I’m sure I started an infinite loop…sort the data it detected and change and sorted the data and detected… I didn’t note any specific property changing…what should I be noting? All I’m trying to do is sort the data each time the window opens.

Thank you and regards,

Did your propertyChange event script check event.propertyName? That’s a common cause of infinite event loops. It should look something like this:

if event.propertyName=='MyCustomDataProp':
	event.source.data = system.dataset.sort(event.newValue, 0, False)

If you don’t check the property name, then your script will be flooded with every possible change, including recursion when you are assigning back into the same component.

Always check the property name in Vision propertyChange events.


@pturmel Hi Phil, thank you!
I get it now, and it works like a charm!
Thanks again for all your help.