Let User Filter Any View

Here’s a great little Action (or Agent) that lets a user filter any categorized view based on whichever category they choose. I suggest putting it in a SmartIcon so that it will be available in any database or view. You may want to put it in an action button at the top of certain categorized views. It is super-fast (much like using an embedded single-category view). I have put error handling for everything that I encountered, so the user will always get a friendly message.

The @SetViewInfo function filters a view down to a single category. Calling it with a null value will reset the view to show all categories.

This is helpful because of an ugly side-effect of @SetViewInfo — filtering is retained even when the user changes to a different view. Sometimes this results in zero documents being shown. Clicking the action button again will show all docs.

By the way, I believe that the column choice does not work in @SetViewInfo( ). In my testing, it only works on the first categorized column.

REM { --- this action button filters a view based on the user's input --- };

tmpVName := @Subset( @ViewTitle; -1 );
@If( tmpVName = "";
   @Return( @Prompt( [Ok]; "Warning"; "This only works when a database
is opened to a view.") );
   @Success );
tmpCol := 1;

REM { produce a list of categories from the current view };
tmpList := @Unique( @DbColumn( "":""; "":""; tmpVName; tmpCol ) );

REM { handle common errors -- reset filtering in an inappropriate view };
warningText := "This action only works in a categorized view where the category
is the first column." + @Char(10) +
  "This will not work in a flat view or in a view where the first column is not
the category";
@If( @IsText( tmpList[1] );
   @Success;
   @Do( @SetViewInfo( [SetViewFilter]; ""; ""; 1); @Return( @Prompt(
[Ok]; "Warning"; warningText ) ) ) );

REM { Let the user pick one category };
tmpChoice := @Prompt( [OkCancelCombo];
"Select a Category for Filter"; "This will filter the view to a single
category." + @Char(13) + "   (specify blank for all)";
""; "" : tmpList );

REM { reminder: expand the view or it may appear empty };
@Command( [ViewExpandAll] ) ;

REM { Set the filter (or clear the filter) };
tmpCName := "sPOAreaName";
@SetViewInfo( [SetViewFilter]; tmpChoice; tmpCName; 1 )