Concept
Change columns on a table visualization with Iron Python. The multi-select list box drives the table visual columns to display.
Script
This script takes the column values from a List box (multiple select) Property Control named column and updates a table visualization. Set the column document property trigger the change_table_visualization_columns Iron Python script when the property changes. The script takes t1 as a script parameter pointing to the table visualization to update.
change_table_visualization_columns.py
# Requires a List box (multiple select) Property Control called "columns" from Spotfire.Dxp.Application.Visuals import VisualContent #get underlying data table #t1 is a Table Visualization script parameter t1=t1.As[VisualContent]() #remove all columns t1.TableColumns.Clear() #get columns (any table is the same. In this case we are using t1) cols = t1.Data.DataTableReference.Columns #add columns: #selectedPreset is a script parameter from the dropdown for col in Document.Properties["columns"]: t1.TableColumns.Add(cols[col])
Use case
Maybe we want to have a dropdown with predefined column selections or "presets" to have the user choose from different "views". For example, a drop down on the home page to display only relevant columns through the analysis on different pages. We can hide the presets from the user or have them on a different configuration tab.
Use case script
Create a List box (multiple select) Property Control for each preset. In this case p1,p2,..,p4 and a Drop down Property Control called presets with the preset names as values
Then associate the presets document property to trigger the update_presets script. This script takes all the table visuals to be updated t1, t2,..,t3 across the analysis and the selectedPreset parameter pointing to the presets document property
update_presets.py
from Spotfire.Dxp.Application.Visuals import TablePlot, VisualContent from Spotfire.Dxp.Data import DataPropertyClass #get underlying data table #t1,t2,..,t3 are script parameters pointing to table visuals t1=t1.As[VisualContent]() t2=t2.As[VisualContent]() t3=t3.As[VisualContent]() #remove all columns t1.TableColumns.Clear() t2.TableColumns.Clear() t3.TableColumns.Clear() #get columns (any table is the same. In this case we are using t1) cols = t1.Data.DataTableReference.Columns #add columns: #selectedPreset is a script parameter from the dropdown for col in Document.Properties[selectedPreset]: t1.TableColumns.Add(cols[col]) t2.TableColumns.Add(cols[col]) t3.TableColumns.Add(cols[col])
Recommended Comments
There are no comments to display.