Bharath Abhishek
Bharath Abhishek

Reputation: 69

Iron python script for creating filters in spotfire

Can some one please provide iron python script to create multiple select list box filter ( with search option). When I click on button in which my script is embeded, data should be filtered for all of my four data tables present in my dashboard page.

I have written some script but it is working if there is only one data table present, I am facing some error when I try to apply the filter for data in multiple data tables.

from Spotfire.Dxp.Applica‌​tion 
import Filters as filters 

CurPanel = Document.ActivePageR‌​eference.FilterPanel 
FilterA = CurPanel.TableGroups‌​[0].GetFilter("column‌​name") 
CheckBoxes = FilterA.FilterRefere‌​nce.As[filters.CheckB‌​oxFilter]() 
strCityL = Document.Properties[‌​"propertyname"] 
   for CheckBoxVal in CheckBoxes.Values: 
       CheckBoxes.Uncheck(C‌​heckBoxVal) 
   for strVal in strCityL: 
       CheckBoxes.Check(st‌​rVal) 

Above script is for one data table and I cannot search my filter values

Thanks

Upvotes: 3

Views: 6216

Answers (1)

niko
niko

Reputation: 3974

the following code should get you there. I've documented so that you can have some context for each line and hopefully reproduce this for any other filter you need. in fact, I think the only other filter that's really very different from this is the RangeFilter, but that's another post somewhere :)

"""
update the specified ListBox filter selection based on a parameter

Parameters to be created:
table  -- the string name of the data table that will be filtered
column -- the string name of the column to filter
          IMPORTANT: set this filter type to ListBox using the Filters panel
values -- a CSV string of the values to be selected
"""

# get the data table reference
dt = Document.Data.Tables[table]
# format our values into a list
vals = values.split(',')

# for debugging; safe to remove
print("values:")
print(vals)

# import the necessary Spotfire classes
from Spotfire.Dxp.Application.Filters import ListBoxFilter, FilterPanel

# using the default Filtering Scheme and the supplied Data Table name, get the filter by its Column name
filter = Document.FilteringSchemes.DefaultFilteringSchemeReference[dt][column]
# cast it as a ListBox filter
lb = filter.As[ListBoxFilter]()

# reset the filter to its default state
lb.Reset()
# set the values according to the script parameter
lb.SetSelection(vals)
# OPTIONAL: select (true) or deselect (false) the "(All)" option
lb.IncludeAllValues = False
# OPTIONAL: select (true) or deselect (false) the "(Empty values)" option
lb.IncludeEmpty = False

# for debugging: safe to remove
print("filter selection:")
print(filter)

while there's really only one way to set a filter, there are a number of ways to go about getting the filter reference. this code (line #23) is, as far as I've discovered, the simplest and easiest to read code for selecting filters. your mileage may vary depending on your analysis and requirements.

Upvotes: 5

Related Questions