cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
wr
wr
Level II

Data filter script

I am filtering data using values in a column. Is it possible to attach a script to the data filter so that the script runs whenever the a new column value is selected in the filter?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: Data filter script

Building on Dan's reply, try:

 

 

NamesDefaultToHere(1);
 
// Some data
dt = New Table( "Fruits",
  Add Rows( 3 ),
  New Column( "Fruit",
  Character,
  "Nominal",
  Set Values( {"Pear", "Apple", "Orange"} )
  )
  );

// A report with a local data filter
gb = dt << Graph Builder(
  Size( 528, 448 ),
  Show Control Panel( 0 ),
  Show Legend( 0 ),
  Variables( X( :Fruit ) ),
  Elements( Bar( X, Legend( 3 ) ) ),
  Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) )
  );
 
// Row state handler function
doSomethingWithSelection = Function({x}, {Default Local}, Beep(); Wait(0.1); Beep() );
 
// Get a reference to the report
gbReport = gb << Report;
 
// See what messages the data filter display box understands (prints to the log)
ShowProperties(gbReport[OutlineBox(1)]);
 
// Assign the row state handler to the local data filter display box
rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(doSomethingWithSelection);

 

View solution in original post

9 REPLIES 9

Re: Data filter script

The data filter manipulates the row states of the data table (global filter) or a private set of row states (local filter).  You can use dt<<Make RowState Handler(function) to perform actions on global filter changes, or box<<Make RowState Handler(function) for a local data filter.  Since there can be multiple local filters in a window, the box just needs to be within the report of interest, for example (platform << Report) would work fine.

ian_jmp
Staff

Re: Data filter script

Building on Dan's reply, try:

 

 

NamesDefaultToHere(1);
 
// Some data
dt = New Table( "Fruits",
  Add Rows( 3 ),
  New Column( "Fruit",
  Character,
  "Nominal",
  Set Values( {"Pear", "Apple", "Orange"} )
  )
  );

// A report with a local data filter
gb = dt << Graph Builder(
  Size( 528, 448 ),
  Show Control Panel( 0 ),
  Show Legend( 0 ),
  Variables( X( :Fruit ) ),
  Elements( Bar( X, Legend( 3 ) ) ),
  Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) )
  );
 
// Row state handler function
doSomethingWithSelection = Function({x}, {Default Local}, Beep(); Wait(0.1); Beep() );
 
// Get a reference to the report
gbReport = gb << Report;
 
// See what messages the data filter display box understands (prints to the log)
ShowProperties(gbReport[OutlineBox(1)]);
 
// Assign the row state handler to the local data filter display box
rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(doSomethingWithSelection);

 

wr
wr
Level II

Re: Data filter script

Brilliant - thanks.

cis_pete
Level III

Re: Data filter script

I have a similar problem. I would like to store the script of a local data filter of a graph builder in a string variable every time the filter changes. My problem with the script above is how to access the local data filter in the doSomethingWithSelection function.

The following line does not work, it does not give the data filter script:

string = gbreport[outlinebox(1)] << get script

ian_jmp
Staff

Re: Data filter script

To message the local data filter, you need to get a reference to it. Try something like:

 

 

NamesDefaultToHere(1);
 
// Some data
dt = New Table( "Fruits",
  Add Rows( 3 ),
  New Column( "Fruit",
  Character,
  "Nominal",
  Set Values( {"Pear", "Apple", "Orange"} )
  )
  );
 
// A report with a local data filter
gb = dt << Graph Builder(
  Size( 528, 448 ),
  Show Control Panel( 0 ),
  Show Legend( 0 ),
  Variables( X( :Fruit ) ),
  Elements( Bar( X, Legend( 3 ) ) )
  );
ldf = gb << Local Data Filter( Mode, Add Filter( columns( :Fruit ) ) );
 
// Row state handler function
doSomethingWithSelection = Function({x}, {Default Local},
  currentScript = ldf << getScript;
  ClearLog();
  Print(currentScript);
);
 
// Get a reference to the report
gbReport = gb << Report;
 
// Assign the row state handler to the local data filter display box
rsh = gbReport[OutlineBox(1)] << MakeRowStateHandler(doSomethingWithSelection);

 

cis_pete
Level III

Re: Data filter script

Thank you, that works. It is really easy if you know how to do it

 

My next question is probably also quite easy for you:

I have a local data filter in an application. I want to set a row state handler for it.

 

That's my code:

 

 

DataFilter1 << Add Filter(
                Columns(Eval(filter_parameter)),
                Display(Size( 100, 150 ),List Display)
);
// set OutlineCloseOrientation and title
ldfr = DataFilter1 << report;
ldfr[Outline Box( 1 )] << OutlineCloseOrientation( "Horizontal" );
ldfr[Outline Box( 1 )] << Set Title("Filter");
 
// set row state handler - both versions do not work
DataFilter1 << Make Row State Handler(DataFilter1_handler);
ldfr[Outline Box( 1 )] << Make Row State Handler(DataFilter1_handler);
 
DataFilter1_handler = function({x},
    show("row state handler function");
);

 

cis_pete
Level III

Re: Data filter script

One further question about the local data filter in your example:

How can you remove the filter by code ("remove local data filter" if you do it manually)?

I tried these commands:

// works

ldf << clear;

// does not work

ldf << close;

ldf << remove;

ldf << close window;

ldf << delete;

Re: Data filter script

In JMP 11, the << close command would not have an effect on a filter that was visible.  Changes in JMP 12 have made this work.

As a workaround for JMP 11 you could use:

gb << Remove Local Data Filter;

Re: Data filter script

Both of your solutions will work, but you do need to assign the result to something:

rsh = DataFilter1 << Make Row State Handler(DataFilter1_handler);


The row state handler is an object that is returned to you.  Since it wasn't stored anywhere it went away!