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

How to custom sort the multiple column in the table visualization ?

Rupinder Kaur 2

Recommended Posts


There are already existing examples for this in the Iron Python script examples in the community wiki that you can refer to

To create a custom sort order


Use the DataColumnProperties.SetCustomSortOrder method:



IronPython script to Set Custom Sort Order


(C# example but may also help you)

How to set Custom Sort order on a given field (Data Column) using using TIBCO Spotfire® C# API


To apply sort order to a table plot


Use methods (primarily Add and Clear) in the TableSortInfoCollection Class:



"How to sort a column from a given data table in TIBCO Spotfire® using IronPython Scripting"



Note: Creating a custom sort order and applying the sorting can of course be done manually, without the need for any scripting, as well.

Link to comment
Share on other sites

Thanks for replying. I have already looked into all these links. I need something that can be invoked automatically on page load.

I tried to write the code in Python, but I am stuck at the end when I have to set the column value with sorted values in the data table. Also, how can I sort the other columns in the same script?

from Spotfire.Dxp.Data import DataValue

from System import Array, Type

from Spotfire.Dxp.Data import DataPropertyClass 

from Spotfire.Dxp.Data import *

from System.Collections.Generic import List

# Specify the table and column name you want to custom sort 

table = Document.Data.Tables["DEFAULT_table"] 

cursor = DataValueCursor.CreateFormatted(table.Columns["Category"])

 # Define your custom sorting order 

customSortOrder = ["tw_monitoring","tw_ods","tw_proactive","predict"] 

# Function to get the custom sort order for a value 

def getCustomSortOrder(value):

 return customSortOrder.index(value)

# Get the data from the specified column 

valData = List [str]()

#iterate through table column rows to retrieve the values

for row in table.GetRows(cursor):

#rowIndex = row.Index ##un-comment if you want to fetch the row index into some defined condition

value = cursor.CurrentValue

if value <> str.Empty:


valData = List [str](set(valData))

#print valData;

#sorting the value

sortedValues= sorted(valData,key=getCustomSortOrder)

#print sortedValues

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