Jump to content
We've recently updated our Privacy Statement, available here. ×

Ironpython Script for column custom sort order not responding


Amit Kumar 16

Recommended Posts

Hi,

Thanks in advance.

I have a dropdown which contains unique value from a column of type date. I need to display the data in descending order. So I Used the below script for that :

-------------------------------------------------------------------------------------------------------------------------------

from System.Reflection import Assembly

from Spotfire.Dxp.Data.Collections import *

from System.Runtime.Serialization import ISerializable

from System.Collections import IComparer

from System.Collections.Generic import IComparer

 

values = Document.Data.Tables['Dangling Revenue Report'].Columns['BILL PERIOD'].RowValues.GetEnumerator()

myValues = []

for val in values:

myValues.Add(val.ValidValue)

myValues.sort(reverse=True)

Document.Data.Tables['Dangling Revenue Report'].Columns['BILL PERIOD'].Properties.SetCustomSortOrder(myValues)

-------------------------------------------------------------------------------------------------------------------------------------------------------------

 

I have used the above script at many places and it is working fine but for a particular report, as soon as I execute the script, the whole report gets stuck and it shows "Not responding".

Any idea on this.

Link to comment
Share on other sites

Does the behavior change when you check for valid values Based on your indentation, the script was sorting after the addition of every value which isn't necessary.

from System.Reflection import Assembly

from Spotfire.Dxp.Data.Collections import *

from System.Runtime.Serialization import ISerializable

from System.Collections import IComparer

from System.Collections.Generic import IComparer

column = Document.Data.Tables['Dangling Revenue Report'].Columns['BILL PERIOD']

values = column.RowValues.GetEnumerator()

myValues = []

for val in values:

if val.HasValidValue: #exclude empty values

myValues.Add(val.ValidValue)

myValues.sort(reverse=True)

column.Properties.SetCustomSortOrder(myValues)

Link to comment
Share on other sites

  • 7 months later...

Hi all,

 

First, thank you very much for providing the script above. I have used it on one of my reports and it seems to work really well so far. I am now able to sort a date column on the filter menu in descending order. This is something I was unable to accomplish using the "custom sort order" option... which was unable to sort any new dates coming from the view/table in descending order.

 

My question is, when exactly does the script above run or perform the appropriate sorting Is it when the report first opens or when someone selects a date column on the drop-down filter menu Just curious.

 

Thank you.

Link to comment
Share on other sites

Hi Kennedyapii.nakuwa,

 

That depends on when you trigger the above scripts in your application. You can do that either on page load using Javascript Ready event, or else you can use data function to trigger the script.

 

For my application, I triggered it using a button and then hide the button. On the page load, called a javascript function to click on the button.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...