Jump to content

How to set a filter on a page other than the active page


Jason Mickey

Recommended Posts

Hello

I have multiple pages in my file which all use the same data table but each page has adifferent filtering schemeof the data (e.g. all data, flagged data, etc.). I want to set a filter on each filtering scheme so that the data shown is narrowed to a subset of the data. I tried the following but it doesn't seem to have any effect.

 

def applyFilterToAllPages(value_to_filter):

# Loop through all pages

for page in Document.Pages:

print(page.Title)

mypanel = page.FilterPanel

myFilter="";

# Replace "column_name" with the column to search for.

myFilter = myPanel.TableGroups[0].GetFilter("column_name")

lbFilter = myFilter.FilterReference.As[filters.ListBoxFilter]()

 

lbFilter.IncludeAllValues=False

 

lbFilter.SetSelection(value_to_filter)

 

 

applyFilterToAllPages(parts)In the above, parts is a Document Property defined by the user.

How can I use IronPython in Spotfire to set each filtering scheme on each page to filter [column_name] to just the values in parts

 

Thanks!

Link to comment
Share on other sites

I tried your code at my end and it works fine i.e. setting filter in all filtering schemes in all pages. Provided you are passing correct value to applyFiltertoAllPages function, correct column name, correct filter type listbox, correct datatable number in tablegroups

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Application import Filters as filters

def applyFilterToAllPages(value_to_filter):

# Loop through all pages

for page in Document.Pages:

print(page.Title)

myPanel = page.FilterPanel

myFilter="";

# Replace "column_name" with the column to search for.

myFilter = myPanel.TableGroups[0].GetFilter("POSITION") ## ensure correct column name and datatable order no i.e. is it first or second or some other number

lbFilter = myFilter.FilterReference.As[filters.ListBoxFilter]() ##Position column needs to be listbox in all filtering schemes

 

lbFilter.IncludeAllValues=False

 

lbFilter.SetSelection(value_to_filter)

 

doc1=Document.Properties["parts"]

applyFilterToAllPages(doc1)

Link to comment
Share on other sites

Hi Khushboo

 

Thanks for the reply!

 

I have verified that the column name I'm filtering on ("column_name" in the sample code) is in the same spot in all the filters and is a listbox on all filters.

 

My file also only has 1 data table in it so the table number is the same across all pages (unless I completely misunderstand the TableGroups parameter.

 

Unfortunately, it still does not set the filters on the filtering schemes of other pages.

 

I did notice that you changed my placeholder "column_name" with "POSITION". Was that intentional Should I be referring to the Number position on the filter panel for the column I want to set the filter for (in my case, it is the 2nd column in each filtering scheme so that would be 1, per Python's numbering methods)

 

 

 

Thanks!

Link to comment
Share on other sites

Not sure what error you are getting, but execute it in IronPython script editor in Spotfire and see what error you are getting. I see that in your code mypanel variable is declared with 'p'as lowercase in it but while using it, it is used with uppercase (myPanel).

Also, you mentioned that parts is a document property defined by the user. You are directly using it in your code. You need to collect it in a variable and then pass it to the function. Or you can directly passDocument.Properties["parts"] in your function.

You can refer to the attached analysis file where I am able to set a filter on each filtering scheme with your code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...