简体   繁体   English

Iron Python脚本,用于在Spotfire中创建过滤器

[英]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). 可以请一个人提供python脚本来创建多个选择列表框过滤器(带有搜索选项)。 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 谢谢

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 :) 实际上,我认为与此唯一非常不同的其他过滤器是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)

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. 据我发现,这段代码(第23行)是最简单,最容易阅读的用于选择过滤器的代码。 your mileage may vary depending on your analysis and requirements. 您的里程可能会因您的分析和要求而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM