Rupinder Kaur 2 Posted October 11, 2023 Share Posted October 11, 2023 Need to custom sort 5 columns in the data table in Spotfire table visualization. Can someone provide the script/ data function to implement. Thanks!for ex col1- original Values - A, B , C , D sort : C, A, D, B Link to comment Share on other sites More sharing options...
Fredrik Rosell Posted October 11, 2023 Share Posted October 11, 2023 Hello,There are already existing examples for this in the Iron Python script examples in the community wiki that you can refer toTo create a custom sort order=============================Use the DataColumnProperties.SetCustomSortOrder method:https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/html/M_Spotfire_Dxp_Data_DataColumnProperties_SetCustomSortOrder.htmExamples IronPython script to Set Custom Sort Orderhttps://community.spotfire.com/s/article/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# APIhttps://community.spotfire.com/s/article/How-to-set-Custom-Sort-order-on-a-given-field-Data-Column-using-using-TIBCO-Spotfire-C-APITo apply sort order to a table plot===================================Use methods (primarily Add and Clear) in the TableSortInfoCollection Class:https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/html/T_Spotfire_Dxp_Application_Visuals_TableSortInfoCollection.htmExample "How to sort a column from a given data table in TIBCO Spotfire® using IronPython Scripting"https://community.spotfire.com/s/article/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 More sharing options...
Rupinder Kaur 2 Posted October 11, 2023 Author Share Posted October 11, 2023 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 DataValuefrom System import Array, Typefrom 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 valuesfor 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.Add(value)valData = List [str](set(valData))#print valData;#sorting the valuesortedValues= sorted(valData,key=getCustomSortOrder)#print sortedValues Link to comment Share on other sites More sharing options...
Gaia Paolini Posted October 12, 2023 Share Posted October 12, 2023 Did you want to custom sort the data table, or to sort a table visualization? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now