有人可以提供 iron python 脚本来创建多个选择列表框过滤器(带有搜索选项)。当我单击嵌入了我的脚本的按钮时,应该为我的仪表板页面中存在的所有四个数据表过滤数据。
我写了一些脚本,但如果只有一个数据表,它就可以工作,当我尝试对多个数据表中的数据应用过滤器时,我遇到了一些错误。
from Spotfire.Dxp.Application
import Filters as filters
CurPanel = Document.ActivePageReference.FilterPanel
FilterA = CurPanel.TableGroups[0].GetFilter("columnname")
CheckBoxes = FilterA.FilterReference.As[filters.CheckBoxFilter]()
strCityL = Document.Properties["propertyname"]
for CheckBoxVal in CheckBoxes.Values:
CheckBoxes.Uncheck(CheckBoxVal)
for strVal in strCityL:
CheckBoxes.Check(strVal)
上面的脚本是针对一个数据表的,我无法搜索我的过滤器值
谢谢
最佳答案
下面的代码应该能让你到达那里。我已经记录下来,以便您可以为每一行提供一些上下文,并希望为您需要的任何其他过滤器重现它。事实上,我认为唯一与此截然不同的过滤器是 RangeFilter,但那是某处的另一篇文章:)
"""
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)
虽然实际上只有一种方法可以设置过滤器,但是有很多方法可以获取过滤器引用。据我所知,这段代码(第 23 行)是用于选择过滤器的最简单易读的代码。根据您的分析和要求,您的里程可能会有所不同。
关于ironpython - 用于在 spotfire 中创建过滤器的 Iron python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38974285/