Sorting a Graphical Table visualization in TIBCO Spotfire® using IronPython

Last updated:
10:27am Jun 29, 2020

Back to main IronPython scripting page


This example demonstrates how to set the sort order in a Graphical Table visualization

Code Sample

# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.

from Spotfire.Dxp.Application.Visuals.Miniatures import GraphicalTable
from Spotfire.Dxp.Application.Visuals import *

gt = MyGraphTable.As[GraphicalTable]()
for col in gt.Columns:
 if col.Title == "Sales":
  sort_info = vi.SortInfos.TryGetSortInfo(col)
  if str(sort_info[1].SortMode) == "Ascending":

#MyGraphTable - Graphical table visualization script parameter


License: TIBCO BSD-Style License

Feedback (3)

To use the SortMode code above you first have to add the column in for sorting.   Below is my code which I wrote as a function since I have multiple visualizations to do this for and the bold section is what is missing from the above:

from Spotfire.Dxp.Data import SortOrder

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Application.Visuals.Miniatures import GraphicalTable

def SortingColumns(GT,ColumnName):

 for col in GT.Columns:

  if col.Title == ColumnName: 





Col = "Ind. 2018 Sls" 



luvigz 12:45pm Jul. 16, 2018


Try changing the vi to gt.  It looks like it should refer to the visual.

sort_info = gt.SortInfos.TryGetSortInfo(col)


Peter.U 8:13am Mar. 12, 2018

When I try to execute this code, I'm getting the following error:


Traceback (most recent call last):
  File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging
  File "<string>", line 7, in <module>
NameError: name 'vi' is not defined

Microsoft.Scripting.Runtime.UnboundNameException: name 'vi' is not defined
   at IronPython.Runtime.PythonContext.MissingName(SymbolId name)
   at Microsoft.Scripting.Runtime.LanguageContext.LookupName(CodeContext context, SymbolId name)
   at Microsoft.Scripting.Runtime.RuntimeHelpers.LookupName(CodeContext context, SymbolId name)
   at <module>$1392##1392(Closure , Scope , LanguageContext )
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)


Any ideas of how can I solve that (is "vi" an internal Spotfire variable?)?


oliver.drummond 2:53am Feb. 12, 2018