Donnerstag, 25. Juni 2020

Show or hide Breadcrumbs in APEX Apps

You may want to add a global control to show or hide the breadcrumbs below the page title. This blog post explains how you can do that. Since users can always return to the home page of your app, by clicking on the Application title, it is OK to hide the breadcrumbs in some situations.
A Region can be set to be Customizable, but that affects only the current page.    
You may want to give the users control to hide and show the Breadcrumbs when they don't need it, with a global switch. The control can be set by the online user via the Navigation Bar menu with the following method.

Add a Application Item
Name : APP_DISPLAY_BREADCRUMBS 
Add an Application Computation
Computation Item : APP_DISPLAY_BREADCRUMBS
Computation Point : On New Instance 
Computation Type : PL/SQL Expression 
Computation  : NVL(APEX_UTIL.GET_PREFERENCE(:OWNER || ':DISPLAY_BREADCRUMBS'), 'YES')

Add an Application Process
Name : Set Display Breadcrumbs
Sequence : 100 
Process Point : On Load: Before Header 
PL/SQL Code:
:APP_DISPLAY_BREADCRUMBS := case when :REQUEST = 'DISPLAY_BREADCRUMBS_ON' then 'YES' else 'NO' end;
APEX_UTIL.SET_PREFERENCE(:OWNER || ':DISPLAY_BREADCRUMBS', :APP_DISPLAY_BREADCRUMBS);
Condition Type : PL/SQL Expression 
Expression 1 : 
:REQUEST IN ('DISPLAY_BREADCRUMBS_ON','DISPLAY_BREADCRUMBS_OFF')
Add Navigation Bar entries 
Edit list 'Navigation Bar' and add 2 entries. 
first entry
Parent List Entry &APP_LOGIN_NAME 
Sequence : 100 
Image/Class : fa-toggle-on 
List Entry Label : Hide Breadcrumbs
Target type : Page in this Application 
Page : &APP_PAGE_ID.
Request : DISPLAY_BREADCRUMBS_OFF
Condition type : Value of Item / Column in Expression 1 = Expression 2 
Expression 1 : APP_DISPLAY_BREADCRUMBS 
Expression 2 : YES 
second entry
Parent List Entry &APP_LOGIN_NAME 
Sequence : 110 
Image/Class : fa-toggle-off 
List Entry Label : Display Breadcrumbs
Target type : Page in this Application 
Page : &APP_PAGE_ID.
Request : DISPLAY_BREADCRUMBS_ON
Condition type : Value of Item / Column in Expression 1 = Expression 2 
Expression 1 : APP_DISPLAY_BREADCRUMBS 
Expression 2 : NO 

Load each page that has a Breadcrumbs region 
Click on the Region named Breadcrumbs
Change the Server-side Condition 
Type : Item = Value 
Item : APP_DISPLAY_BREADCRUMBS
Value : YES 
or when you also whant to hide the region in printer friendly mode
Type : PL/SQL Expression 
PL/SQL Expression :
:PRINTER_FRIENDLY = 'NO' AND :APP_DISPLAY_BREADCRUMBS = 'YES'

The method is demonstrated in a demo app. After login click on the username menu entry in the top menu.