2016-08-16 81 views
2

有人可以提供鐵python腳本來創建多個選擇列表框過濾器(帶有搜索選項)。當我點擊嵌入腳本的按鈕時,應該過濾我的儀表板頁面中顯示的所有四個數據表的數據。用於在spotfire中創建過濾器的鐵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) 

上面的腳本是一個數據表,我不能搜索我的過濾器值

感謝

+0

請提供Spotfire.Dxp.Application進口過濾器,你有迄今腳本:) – scsimon

+0

作爲過濾 CurPanel = Document.ActivePageReference.FilterPanel FilterA = CurPanel.TableGroups [0] .GetFilter( 「列名」) 的CheckBox = FilterA.FilterReference.As [filters.CheckBoxFilter]() strCityL = Document.Properties在CheckBoxes.Values [ 「PROPERTYNAME」] 爲CheckBoxVal:CheckBoxes.Uncheck(CheckBoxVal) 用於strVal在strCityL: \t CheckBoxes.Check( strVal) 上面的腳本是針對一個數據表的,我無法搜索我的過濾器值。 –

+0

我不是偉大的鐵IronPy通過何塞和其他一些人。這是一個很好的鏈接。 http://spotfired.blogspot.com/2014/03/change-filters-programatically-from.html 這是他的個人資料http://stackoverflow.com/users/922290/jleviaguirre @jleviaguirre – scsimon

回答

3

下面的代碼應該讓你那裏。我已經記錄下來,以便您可以爲每行添加一些上下文,並希望爲您需要的任何其他過濾器複製此空間。其實,我覺得唯一的其他過濾器,這真的很不同,這是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行)是用於選擇過濾器的最簡單和最容易閱讀的代碼。您的里程可能會根據您的分析和要求而有所不同。

+1

希望我可以邀請兩次文檔! – scsimon