Shane
Shane

Reputation: 51

Change multiple default filters based on the value chosen from a dropdown property control: Spotfire

how can I change multiple default filters based on the value chosen from a dropdown property control?

How do I achieve this functionality?

Any help is appreciated.

Upvotes: 1

Views: 2658

Answers (1)

niko
niko

Reputation: 3974

there's not a lot of detail in your question, so I'm making a lot of assumptions here, most importantly that you are dealing with ListBox filters; this code will not work with other filter types. this is the dataset I'm using:

NAME    DEPARTMENT
alice   marketing
bob     sales
charley sales
dave    engineering
  1. in the analysis, add a Text Area and insert a Dropdown Property Control
  2. click New... to create a new Document Property called Department, which will be a String and contains the default value sales
  3. Set property value through: Unique values in column, and choose the Department column
  4. click Script... and in the dialog, choose Execute the script selected below, then hit New...
  5. give the script a name like ChangeFilter. Add... a Script parameter
  6. call the Script parameter department_name, set it to String, then select Property:, and finally click Select Property... to set it to our department Document Property
  7. paste in the following code snippet:
# import the ListBoxFilter class
from Spotfire.Dxp.Application.Filters import ListBoxFilter

# locate the data table and grab the filter collection
dt = Document.Data.Tables["Data Table"]
filters = Document.FilteringSchemes.DefaultFilteringSchemeReference[dt]

# repeat the below lines for any other filters you would like to change

# choose the filter we are interested in
f = filters["department"].As[ListBoxFilter]()

# unset "IncludeAllValues" or nothing we change will matter
f.IncludeAllValues = False
# set the value we are interested in
f.SetSelection(department_name)
  1. accept all dialogs until you're back at your analysis, and test.

Upvotes: 1

Related Questions