Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

Filtering Schemes (current, all, add, set and other tricks)

from Spotfire.Dxp.Application.Filters import FilterPanel 
from Spotfire.Dxp.Application.Layout import PanelState 

filterPanel = Document.ActivePageReference.FilterPanel

#Show (or hide) the filter panel (when docked)
filterPanel.Visible = True

#Show undocked filter panel 
filterPanel.PanelState = PanelState.Popover

#Hide undocked filter panel 
filterPanel.PanelState = PanelState.Docked 
filterPanel.Visible=False

#Get the current filtering scheme name
print Document.ActiveFilteringSelectionReference.Name

#List all the filtering schemes
for scheme in Document.FilteringSchemes: 
  print scheme.FilteringSelectionReference.Name

#Get a specific filtering 
Document.FilteringSchemes[Document.Data.Filterings["Stores"]]

#List all the filtering selection
for scheme in Document.Data.Filterings:
   print scheme.Name

#Get a specific filtering Selection
filteringSelection = Document.Data.Filterings["Stores"]

#Reset all filters from a specific filtering scheme
dataFiltering = Document.Data.Filterings["Stores"]
filteringScheme = Document.FilteringSchemes[dataFiltering]
filteringScheme.ResetAllFilters()

# Add a new data filtering selection (DataFilteringSelection)
dataFilteringSelection = Document.Data.Filterings.Add("My Filtering")

# A filtering scheme has now been implicitly added for the new data filtering selection (FilteringScheme).
myFilteringScheme = document.FilteringSchemes[dataFilteringSelection]

#Let the active page use the new filtering scheme. 
filterPanel.FilteringSchemeReference = myFilteringScheme

#Make sure that the filter panel shows the filtering scheme menu. 
Document.FilteringSchemes.FilteringSchemeMenuVisible = true;

#get a reference to the current filtering scheme
currentFiltering = Document.FilteringSchemes[Document.ActiveFilteringSelectionReference]

#set search expression to current filtering scheme to show only modified filters Document.ActivePageReference.FilterPanel.InteractiveSearchPattern = "status:modified"


8 comments:

VjoyeeRocks said...

For listing all filtering schems, on writing the syntax and running, I get below error:

AttributeError: 'FilteringScheme' object has no attribute 'Name'

My requirement is to change filter values of another filter scheme, that which is currently hidden and is also no the default one, by clicking a button and using iron python.

Jose Leviaguirre said...

Hello Digvijoyee,

try:

Spotfire.Dxp.Application.Filters.FilteringSchemeCollection["yourfilterschemename"]

Documentation here:
https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/?topic=html/N_Spotfire_Dxp_Application_Filters.htm

VjoyeeRocks said...

Hi Jose,

Thanks !!

Actually I just wanted to change filter values of a filtering scheme by changing filter values of a different filtering scheme and the different scheme I had already created.

But any how I created one solution to do this. The only thing is that I had to create a new tab and thiis didn't become an issue for me as mine is a guided analysis dashboard.

Below is my code (the filter in code is the Date filter (column name is Date):

--------------------------------------------------------------

import Spotfire.Dxp.Application.Filters as filters

i=0

for scheme in Document.FilteringSchemes:
if (i==1):
for item in Document.Pages:
if (item.Title=="Test Page DO NOT DELETE OR RENAME !!!"):
item.FilterPanel.FilteringSchemeReference=scheme
i=i+1

myfilter=item.FilterPanel.TableGroups[0].GetFilter("Date").FilterReference.As[filters.ListBoxFilter]()
myfilter.IncludeAllValues= False
myfilter.SetSelection(Document.Properties["Date"])

haydenridd said...

Hello! This is really old but just wanted to post a follow up for anyone else using this as a resource. The reason for the "AttributeError: 'FilteringScheme' object has no attribute 'Name'" error occurs is because a "FilteringScheme" object does not have a "Name" property. To get what you are looking for you simply need to change:
for scheme in Document.FilteringSchemes:
print scheme.Name

To:
for scheme in Document.FilteringSchemes:
print scheme.FilteringSelectionReference.Name

Cheers!

Hayden

Jose Leviaguirre said...

Thank you Hayden! I fixed to code with your suggestions.

Unknown said...

Hi Digvijoyee,
I saw your post and I am actually looking for the same kind of code. I have a filtering schema. I need to capture the some of the filter values to change the cross table value axis formulas based on which filter values they have selected and apply same filtering changes to another schema. Can you please share code that applies one filtering schema changes to another filtering Schema after clicking a button. My analysis has bunch of filtering schema's but I wanted 2 of them needs to be in synch.

Thanks,
Suneetha

Unknown said...

Hi All,

I wanted to get the coulmn Name of the Active filters available in the Current Page..

Jose Leviaguirre said...

Hello Ameet,

Try this code:

tableGroups = Document.ActivePageReference.FilterPanel.TableGroups
for tableGroup in tableGroups:
for filterHandle in t.FilterHandles:
filter = filterHandle.FilterReference

#print available filters (and visibility status)
print '[',tableGroup,'].[',filter.Name,'].Visible = ',h.Visible

More information here: http://spotfired.blogspot.com/2014/08/reset-visible-filters.html