Sorting

These IronPython scripts below show how to modify any of the Cross Table visualization settings found on the Sorting tab of the Cross Table Properties dialog box in the Spotfire user interface.
Note

In each of the scripts below, it is assumed that the MyVis variable references the targeted visualization. See here for more information about referencing visualizations.

Change Sort Rows By Options

The IronPython script below shows how to update any of the cross plot properties associated with row sorting. In order from top to bottom in the user interface, this includes:

  1. Sort rows by: (a specific category)
  2. Sort rows ascending or descending
  3. Ignore hierararchy option
  4. Show only the first number of rows option and value
  5. Indicate hidden rows option
from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Data import SortOrder

myVis = myVis.As[Visualization]()

# 1. Sort rows by a specific category:
# The simplest scenario, with a single text category
myVis.SortRowsCategory = CategoryKey("Category A")
# OR
# When using a hierarchy of text categories
# The UI dropdown would show something like: Category A >> Group B
myVis.SortRowsCategory = CategoryKey("Category A", "Group B")
# OR
# When using a hierarchy of mixed type categories (e.g. text and number)
# The UI dropdown would show something like: Category A >> 4
myVis.SortRowsCategory = CategoryKey("Category A", 4)

# 2. Sort rows ascending or descending:
myVis.SortRowsOrder = SortOrder.Ascending
# OR
myVis.SortRowsOrder = SortOrder.Descending

# 3. Ignore row hierarchy for sorting (UI checkbox checked):
myVis.SortRowsMode = CrossTablePlot.SortMode.Global
# OR
# Use row hierarchy for sorting (UI checkbox unchecked)
myVis.SortRowsMode = CrossTablePlot.SortMode.Leaf

# 4. Show only the first number of rows:
myVis.ShowTopNRows = True
# Set the first number of rows to show:
myVis.TopNRowCount = 5

# 5. Indicate hidden rows:
myVis.IndicateHiddenRows = True

Change Sort Columns By Options

The IronPython script below shows how to update any of the cross plot properties associated with column sorting. In order from top to bottom in the user interface, this includes:

  1. Sort columns by: (a specific category)
  2. Sort columns ascending or descending
  3. Show only the first number of columns option and value
  4. Indicate hidden columns option
from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Data import SortOrder

myVis = myVis.As[Visualization]()

# 1. Sort columns by a specific category:
# The simplest scenario, with a single text category
myVis.SortColumnsCategory = CategoryKey("Category A")
# OR
# When using a hierarchy of text categories
# The UI dropdown would show something like: Category A >> Group B
myVis.SortColumnsCategory = CategoryKey("Category A", "Group B")
# OR
# When using a hierarchy of mixed type categories (e.g. text and number)
# The UI dropdown would show something like: Category A >> 4
myVis.SortColumnsCategory = CategoryKey("Category A", 4)

# 2. Sort columns ascending or descending:
myVis.SortColumnsOrder = SortOrder.Ascending
# OR
myVis.SortColumnsOrder = SortOrder.Descending

# 3. Show only the first number of columns:
myVis.ShowTopNColumns = True
# Set the first number of columns to show:
myVis.TopNRowCount = 5

# 4. Indicate hidden columns:
myVis.IndicateHiddenColumns = True
Welcome!

The purpose of this website is to provide a comprehensive, accurate, and efficient IronPython reference for Spotfire developers.