cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
john_madden
Level VI

How to close existing table data filter at beginning of new script

I have a script that adds a filter to a data table that is already open. Sometimes a user already has (manually) opened a data filter on that table before the script is invoked.

Such an existing data filter seems to interfere with my new, scripted filter taking efffect -- even though I do a dt << Clear Row States at the beginning of my script.

So I'd like to have a statement at the beginning of my script that closes any/all existing table filter(s). But I can't figure out how to reference an arbitrary open data filter that someone else has already created outside my own script. Suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: How to close existing table data filter at beginning of new script

@john_madden,

 

If you only want the reset selection button pressed at some point here is script.

This script

  1. looks for a table data filter.
  2. If found, it looks for a visible button with the title "Reset selection". 
  3. If the button is found, click it.
Names Default to Here(1);

dt  = current data table();
dtname = dt << get name;
winList = get window List();

found = 0; _xzz=empty();
For(i=nitems(winList), i>=1 & !found, i--,
  nme = winList[i] << Get Window Title; 
  If(Starts With(nme,"Data Filter") & Contains(nme,dtname), 
    found =1;
    _xzz = winList[i] <<xpath("//IfBox[@isTrue='true']//ButtonBox[@title='Reset selection']")
    if(nitems(_xzz) > 0, _xzz[1] << Click);
    );    	
);

If you want this action to be taken more than at the start of your script, you will need a handler or subscription to define when it needs to be run.

 

Hope that helps.

 

XPath syntax can look a bit strange, but it is very powerful since the JMP report tree structure has an associated XML description.  I've attached a script written for chapter 6, section "Scriptable Object and XPath" of  JSL Companion, Applications of the JMP Scripting Language, Second Edition . The script provides a limited introduction, a few simple examples, and links to learn more.

View solution in original post

8 REPLIES 8
gzmorgan0
Super User (Alumni)

Re: How to close existing table data filter at beginning of new script

@john_madden ,

 

As of JMP 14, the only method I know how to do is via brute force. See below. Note Start Over clears the table selection state

Names Default to Here(1);

dt  = current data table();
dtname = dt << get name;
winList = get window List();

found = 0;
For(i=nitems(winList), i>=1 & !found, i--,
  nme = winList[i] << Get Window Title; 
  If(Starts With(nme,"Data Filter") & Contains(nme,dtname), 
    found =1;
    (winList[i] << child << get scriptable object) << Start Over;
    
    window(nme) << close window();
    );
    show(i, nme, found);
    	
);

If you are working with an application and the user adds a local data filter and your analyses needs it removed, you can  use XPath to find it, get the script, delete the found filter, dow your analysis and restore via the saved script.

 

The attached JSL below shows how to use XPath to get a handle to a data filter on a specific analysis.

 

Hope that helps.

 

john_madden
Level VI

Re: How to close existing table data filter at beginning of new script

That works, but I think I realized in a little more detail what is happening, which might suggest another solution.

If you create have a table with a filter, and then you change the table row selection elsewhere (this is the case for me), there appears the following in the data filter:

screenshot_475.png

 

 

 

 

 

I think what I need is the script equivalent of pressing the "Reset selection" button.

Is this possible?

gzmorgan0
Super User (Alumni)

Re: How to close existing table data filter at beginning of new script

@john_madden,

It is not clear to me what action you want. For example:

  • Ex1: Suppose Big Class was open the associated Data Filter was on column age and 13 and 14 year olds were selected in the filter. Then another application selected female 15 year olds. The Reset button would appear. If clicked, it returns the table selecton defined in the table Data Filter. Is that what you want?
  • Ex2: same starting scenario as Ex1, but a user deletes a couple rows from the data table. The Reset button does not appear and the previous selections no longer appear in the Data Filter.

There are methods/functions called "handlers" for a data filter and and a table

  • Make Data Filter Handler
  • Make Row State Handler
  • Subscribe (for a data table)

Once defined/enabled, action can be taken if row states change, rows are deleted, and more.

 

If you are just interested in the Reset button, I suspect (haven't tested it yet), the previous script I sent can be modified to find the Data Filter and if the Reset button is not collapsed (is visible) a click can be sent to it. However, before sending a modified script, a better description of the expected action would be useful.

 

Another consideration, if a user adds a local data filter on a report, the table and if it has a data filter does not reflect user selections from the report's local data filter. 

gzmorgan0
Super User (Alumni)

Re: How to close existing table data filter at beginning of new script

@john_madden,

 

If you only want the reset selection button pressed at some point here is script.

This script

  1. looks for a table data filter.
  2. If found, it looks for a visible button with the title "Reset selection". 
  3. If the button is found, click it.
Names Default to Here(1);

dt  = current data table();
dtname = dt << get name;
winList = get window List();

found = 0; _xzz=empty();
For(i=nitems(winList), i>=1 & !found, i--,
  nme = winList[i] << Get Window Title; 
  If(Starts With(nme,"Data Filter") & Contains(nme,dtname), 
    found =1;
    _xzz = winList[i] <<xpath("//IfBox[@isTrue='true']//ButtonBox[@title='Reset selection']")
    if(nitems(_xzz) > 0, _xzz[1] << Click);
    );    	
);

If you want this action to be taken more than at the start of your script, you will need a handler or subscription to define when it needs to be run.

 

Hope that helps.

 

XPath syntax can look a bit strange, but it is very powerful since the JMP report tree structure has an associated XML description.  I've attached a script written for chapter 6, section "Scriptable Object and XPath" of  JSL Companion, Applications of the JMP Scripting Language, Second Edition . The script provides a limited introduction, a few simple examples, and links to learn more.

john_madden
Level VI

Re: How to close existing table data filter at beginning of new script

Thanks so much, gz. 

 

The xpath function is great! As it happens, I come from an XML background and have used xpath in the past. But I was completely unaware you could use it this way in JMP. And I've found it challenging to navigate display trees until now. So this is a real find. Very helpful!

john_madden
Level VI

Re: How to close existing table data filter at beginning of new script

Fooling around, I found a simple solution:

For( i = N Items( Get Window List() ), i >= 1, i--,
     Try(
         Data Filter[i] << Close;
Data Table[i] << Clear Row States // optional, if you want to
)
);

I had no idea about the Data Filter[i] syntax. Makes it simple. 

hogi
Level XII

Re: How to close existing table data filter at beginning of new script

Data Filter[i]

cool!

Where is this documented?

hogi
Level XII

Re: How to close existing table data filter at beginning of new script

I found in the Scripting Index that one can reference a data table via

dt = data table(i);
dt = data table(name);

and get the name via 

dt << get name();

Is there also a function to get "i".

 

I mean directly, not via

Loc(Get Data Table List(),data table(2))

 

Oh, I just noticed that Data Filters have their own index - independent of the respective Data Tables ...
So Data Fitler[i] cannot be used to access a specific data filter (via data table-> i --> data filter) ?