Columns

These IronPython scripts below show how to modify any of the Table visualization settings found on the Columns tab of the 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.

Add or Remove Columns from the Table Plot

The IronPython script below shows how to add or remove data table columns in a Table Plot visualization in Spotfire. The column sort order is controlled by the order in which they are added programmatically in the script below.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()
dataTable = myVis.Data.DataTableReference

# Remove all columns from "Selected columns:" listbox
# This is equivalent to clicking the "Remove All" button
myVis.TableColumns.Clear()

# Add columns to the "Selected columns:" listbox by column name
# IMPORTANT: The column sort order in the Table Plot matches the order below
myVis.TableColumns.Add(dataTable.Columns.Item["Column 1"])
myVis.TableColumns.Add(dataTable.Columns.Item["Column 2"])
myVis.TableColumns.Add(dataTable.Columns.Item["Column 3"])

# Remove a column from the "Selected columns:" listbox by column name
myVis.TableColumns.Remove(dataTable.Columns.Item["Column 1"])

# Move all "Available columns:" to the "Selected columns:" listbox:
myVis.TableColumns.Clear()  #Clear first to prevent duplicate error
for i in dataTable.Columns:
    myVis.TableColumns.Add(i)

# Get the number of "Selected columns:"
print myVis.TableColumns.Count

# Get the ordered list of all columns shown in the Table Plot:
for i in myVis.TableColumns:
    print i.Name

Change the “Add New Columns Automatically” Option

The script below is equivalent to checking the “Add new columns automatically” checkbox at the bottom of the Columns tab.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

myVis.AutoAddNewColumns = True

Set Column Renderer Options

The IronPython script below is equivalent to selecting either “Link”, “Text”, or “Image from URL” from the Renderer dropdown box at the bottom-right of the Columns tab of the Properties dialog box.

The second part of the script also shows how to set the “Link Renderer Settings”, which in the Spotfire user interface are set by clicking the “Settings…” button below the Renderer dropdown.

from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Application.Visuals.ValueRenderers import *

myVis = myVis.As[Visualization]()
dataTable = myVis.Data.DataTableReference

# Choose "Link" from the "Renderer:" dropdown
linkRenderer = myVis.TableColumns.SetValueRenderer(dataTable.Columns.Item["Column 1"],
                                    ValueRendererTypeIdentifiers.LinkRenderer)
# OR
# Choose "Text" from the "Renderer:" dropdown
myVis.TableColumns.SetValueRenderer(dataTable.Columns.Item["Column 1"],
                                    ValueRendererTypeIdentifiers.DefaultRenderer)
# OR
# Choose "Image from URL" from the "Renderer:" dropdown
imageRenderer = myVis.TableColumns.SetValueRenderer(dataTable.Columns.Item["Column 1"],
                                    ValueRendererTypeIdentifiers.ImageFromUrlRenderer)

# Set the URL template for "Link" or "Image from URL" options above
# The URL template is a string where {$} will be replaced by a data value
linkRenderer.LinkTemplate = "{$}.com"
# OR
imageRenderer.UrlTemplate = "{$}.com"

Set Table Plot Column Widths

This IronPython script is equivalent to clicking and dragging in between column headers on a Table visualization in the Spotfire user interface. Simply edit and/or add more elif statements below based on the column names and number of widths you need to set. The last “else” option will set the width for any columns not referenced directly in the script.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

for i in myVis.TableColumns:
	if i.Name == "Column 1":
		i.Width = 50
	elif i.Name == "Column 2":
		i.Width = 150
	elif i.Name == "Column 3":
		i.Width = 100
	else:
		i.Width = 80  #Width for any column not referenced above
Welcome!

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

If you have any questions, comments, or ideas, feel free to get in touch!