ironpython - 用于在 spotfire 中创建过滤器的 Iron python 脚本

标签 ironpython spotfire

有人可以提供 iron python 脚本来创建多个选择列表框过滤器(带有搜索选项)。当我单击嵌入了我的脚本的按钮时,应该为我的仪表板页面中存在的所有四个数据表过滤数据。

我写了一些脚本,但如果只有一个数据表,它就可以工作,当我尝试对多个数据表中的数据应用过滤器时,我遇到了一些错误。

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) 

上面的脚本是针对一个数据表的,我无法搜索我的过滤器值

谢谢

最佳答案

下面的代码应该能让你到达那里。我已经记录下来,以便您可以为每一行提供一些上下文,并希望为您需要的任何其他过滤器重现它。事实上,我认为唯一与此截然不同的过滤器是 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/

相关文章:

c# - 无法调用采用在不同程序集中定义的类型的参数的函数

ironpython - Spotfire 脚本不受信任

c# - 定期更新屏幕数据的模式

url-redirection - 单击链接后 Spotfire 重定向到主页

c# - 为 IronPython 安装 numpy

python - 创建一个修改了一个元素的新元组

javascript - 停止 jquery 函数在鼠标悬停时淡入淡出

javascript - Spotfire 复选框过滤器项目计数

python - 在表中插入总行数,不使用 Pandas,仅使用循环

calculated-columns - 计算 Spotfire 中特定行的同一列的差异