Tuesday, July 05, 2016

Prevent general row based search in an APEX Interactive Report

At my current project we use Interactive Reports heavily. But in some cases the underlying queries are rather complex and a query without any filter or with just a filter on all columns doesn't perform that well (understatement...). We already implemented a solution to prevent initial loading of the data by adding an additional criterium to the query ( :P400_SEARCH = 'Y' ). The default value of this hidden item is 'N' and on Page Load the value is set to 'Y', so the next search will be executed. But as said, this is good, but not good enough...

So this morning I was looking for a solution to "force" the user to enter a query on one of the columns - either through the "search bar column list" (the magnifier on the left side of the search field) or through the Actions > Filter menu. The first attempt was to use a Dynamic Action that fires on change of the search field, but that doesn't work when the user switches existing filters on or off. So I inspected the debug output of the page and discovered an item named "APXWS_EXPR_1". This item is set when the report is refreshed and contains the value of the first column filter you apply. Subsequently you can have APXWS_EXPR_2 etc. So I added an additional restriction to the query: 

:APXWS_EXPR_1 IS NOT NULL

Thus by just adding one line to the query the user is forced to use at least one column filter - both the "contains" as any other more specific filter works. And I can even delete the previous solution that prevented running the query (actually the query is run, but returns "no data found" in no time) when the user navigates to the page.

As a side note, if you use the general filter on all columns, that value is available on the server as "APXWS_SEARCH_STRING_1" (and _2 etc.)

Post a Comment