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.setAutoCreateRowSorter(True)
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;
gTable.setAutoCreateRowSorter(False)
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()
gTable.setAutoCreateRowSorter(True)
gTable.getRowSorter().setSortKeys(sortList)
gTable.setAutoCreateRowSorter(False)
table = self
gTable = table.getTable()
gTable.setAutoCreateRowSorter(True)
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!
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.
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.
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.
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.
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.