Jump to content
  • Add Columns Dynamically to a Table Visualization via Dropdown


    Customize data table visualization columns from a dropdown with an Iron Python Script

    Concept

    Change columns on a table visualization with Iron Python. The multi-select list box drives the table visual columns to display.

     

    concept.thumb.gif.72876e21f02349e672eb9352957d3d15.gif

     

    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. 

     

    Listbox(multipleselect)PropertyControl.png.45af02f93abef741fcbccc5ff95acbab.png script.thumb.png.ee8092df122c604612922e3b3ec86f60.png

    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.thumb.gif.dcf961deec1320b0ff5290ef9cd6b930.gif

    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

    presets.png.4508224e9c56760288d187f6583786e7.png ddownpresets.png.ed92951d27501bc65963a96d9e148c5e.png

     

    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

    presets_script.thumb.png.dd650982f258d72cb660867e294f7611.png

     

    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])
     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...