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.
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);
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.
Brilliant - thanks.
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
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);