Add a tool to select columns even when in viewing mode
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
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
- Create a text area and add a List Box (Multiple Select). and assign a document property called defaultPreset.
- Select the columns you want to be as the default view
- You can now hide or delete the control. The document property should remain with the selected column values
-
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
Create different presets
Presets are useful to create groups of different columns. The approach is similar to the reset button
- 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
-
Delete the 3 text areas, The preset1,2 and 3 document properties are created as String List data type
-
Add a Drop-down list and assign a document property called presets.
-
Link the preset document property so when it changes it runs the setPreset script. Set the selectedPreset script parameter to the presets property
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
-
Create a button to update the selected preset and add this script called savePreset to it
Document.Properties[preset4update] = Document.Properties["dataTableColumnSelection"]
-
set the preset4update as a script parameter pointing to the presets property
Create a popup
-
Format the multiselect control to make it wider and accommodate for the column width and height as well as the buttons
- Follow the instructions from here
Recommended Comments
There are no comments to display.