Jump to content
  • Data Table Column Picker


    Add a tool to select columns even when in viewing mode

    columnSelector.thumb.gif.e97a7acc001ff3cbff4940ef006e905f.gif


     

    How it works

    An Iron Python script updates the columns from a Table visualization with the selection from a Multiple Selection List Box. There are buttons to reset to the default view or from a pre-defined preset.


    Steps to create this tool

    Basic Functionality

    Step 1:
    Create a text area and add a List Box (Multiple Select). and assign a document property called dataTableColumnSelection


    image.png.392ec59019bc20aa522e5099d0566ba9.pngimage.png.42518b097d25d0a0df236b47578a4424.png

    Step 2:
    Click on the [Script...] button and add the following script so when the value of the document property changes, The script requires a table visualization parameter called 't1'

     

    IronPython Script

    from Spotfire.Dxp.Application.Visuals import TablePlot, VisualContent
    from Spotfire.Dxp.Data import DataPropertyClass
    
    #Script Parameters
    #t1 is a script parameter data table visualization
    
    #Script Settings
    multiSelectColumnsPropertyControl = "dataTableColumnSelection" #multiselect doc prop control
    dataTable = Document.Data.Tables.DefaultTableReference   #reference to the default data table
    
    
    
    def updateColumns(tablePlotvisualRef):
    	tablePlotVisual = tablePlotVisual=tablePlotvisualRef.As[VisualContent]()
    
    	cols = tablePlotVisual.Data.DataTableReference.Columns
    	tablePlotVisual.TableColumns.Clear()
    
    	# 2.2 get document property
    	selection = Document.Data.Properties.GetProperty(DataPropertyClass.Document, multiSelectColumnsPropertyControl).Value
    
    	# 2.3 Parse columns from selection and add to tablePlotVisual
    	for property in selection:
    	   for col in property.split(","): tablePlotVisual.TableColumns.Add(cols[str(col)])
    
    
    
    updateColumns(t1)
    #updateColumns(t2)

     

    
    
    

    Step 3:
    Test the script. It should work adding or removing columns

    Create the reset button

    The reset button sets the table with a predefined number of columns

    1. Create a text area and add a List Box (Multiple Select). and assign a document property called defaultPreset.
    2. Select the columns you want to be as the default view
    3. You can now hide or delete the control. The document property should remain with the selected column values
    4. Add a button that triggers the following script.

      Document.Properties["dataTableColumnSelection"]=Document.Properties[selectedPreset]

      The selectedPreset is a script parameter to pass the name of the document property name. This script transfers the value from the defaultPreset to the dataTableColumnSelection
      image.png.a781e543b002713826f47aecc2376ce9.png


    Create different presets

    Presets are useful to create groups of different columns. The approach is similar to the reset button

    1. Create a 3 text area and add a List Box (Multiple Select). and assign a document property called preset1, preset2 and preset3. Make sure you also select some default columns for each preset
    2. Delete the 3 text areas, The preset1,2 and 3 document properties are created as String List data type
      image.png.2e8d8a6c3dc2547d7dacd253ff0759f6.png 
    3. Add a Drop-down list and assign a document property called presets.
      image.png.721a74c6223f6f0b4cd9899f97536345.png
       
    4. Link the preset document property so when it changes it runs the setPreset script. Set the selectedPreset script parameter to the presets property
      image.png.0d392395379cef269f73e62eded0a560.png

    Create the save preset button

    This button updates the column settings saved on each of the presets from the dropdown. It copies the current dataTableColumnSelection values to the corresponing preset

    1. Create a button to update the selected preset and add this script called savePreset to it

      Document.Properties[preset4update] = Document.Properties["dataTableColumnSelection"]
       
    2. set the preset4update as a script parameter pointing to the presets property
      image.png.31e046d098e13db83d8998dc060b168a.png

     

    Create a popup

    1. Format the multiselect control to make it wider and accommodate for the column width and height as well as the buttons
      image.png.5ad87cff1fee32360b5fa06fdc3bba56.png
    2.  Follow the instructions from here 

    image.png

    image.png

    image.png


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...