Skip to main content

Stinkin' Badges

Ever since APEX 5, the poor Navigation Bar has taken a back seat to the Navigation Menu. And for good reason, as the Navigation Menu offers a much more intuitive and flexible way to provide site-wide navigation that looks great, is responsive and just plain works. However, the Navigation Bar can and does still serve a purpose. Most application still use it to display the Logout link and perhaps the name of the currently signed on user. Some applications use it to also provide a link to a user's profile or something similar.

Another use for the Navigation Bar is to present simple metrics via badges. You've seen the before: the little red numbered icons that hover in the upper-right corner of an iPhone or Mac application, indicating that there's something that needs attention. Whether you consider them annoying or helpful, truth be told, they are a simple, minimalistic way to convey that something needs attention.

Fortunately, adding a badge to a Navigation Bar entry in the Universal Theme in APEX 5 is tremendously simple. In fact, it's almost too simple! Here's what you need to do:
First, navigate to the Shared Components of your application and select Navigation Bar List. From there, click Desktop Navigation Bar. There will likely only be one entry there: Log Out.

2016 01 28 08 40 05

Click Create List Entry to get started. Give the new entry a List Entry Label and make sure that the sequence number is lower than the Log Out link. This will ensure that your badged item displays to the left of the Log Out link. Optionally add a Target page. Ideally, this will be a modal page that will pop open from any page. This page can show the summary of whatever the badge is conveying. Next, scroll down to the User Defined Attributes section. Enter the value that you want the badge to display in the first (1.) field. Ideally, you should use an Application or Page Item here with this notation: &ITEM_NAME. But for simplicity's sake, it's OK to enter a value outright.
Run your application, and have a look:

2016 01 28 08 48 45

Not bad for almost no work. But we can make it a little better. You can control the color of the badge with a single line of CSS, which can easily be dropped in the CSS section of Theme Roller. Since most badges are red, let's make ours red as well. Run your application and Open Theme Roller and scroll to the bottom of the options. Expand the Custom CSS region and enter the following text:

.t-Button--navBar .t-Button-badge { background-color: red;}

Save your customizations, and note that the badge should now be red:

2016 01 28 08 49 49

Repeat for each metric that you want to display in your Navigation Bar.

Comments

Unknown said…
Great little tutorial.

Is there away to have the background color different for two separate badges? I.e. Red for system alerts and another color for simple notifications?
Chimpanzee said…
Great little tip - thanks. I don't think this is documented anywhere but will come in very handy. I've also noticed that you can use the 2nd User Defined Attrubute to add an additional class to the <li> element. You could also enter a Page or Application Item in here that's procedurally set depending on the value, eg:

if :BADGE_VALUE > 0 then
:BADGE_CLASS := 'hot';
else
:BADGE_CLASS := 'neutral';
end if;

This allows you to style the badge differently if action is required using some CSS like

li.hot .t-Button-badge {background-color:red}
li.neutral .t-Button-badge {background-color:gray}

Or you can just declare a static class directly in the 2nd attribute if, like Leigh above, that's all you need.

Thanks again.
Chimpanzee said…
Hi Leigh. See my comment below on how to apply a class to a specific item and thus, style the badge differently.
Unknown said…
Thanks for that appreciate it.

Popular posts from this blog

Formatting a Download Link

Providing file upload and download capabilities has been native functionality in APEX for a couple major releases now. In 5.0, it's even more streamlined and 100% declarative. In the interest of saving screen real estate, I wanted to represent the download link in an IR with an icon - specifically fa-download. This is a simple task to achieve - edit the column and set the Download Text to this: <i class="fa fa-lg fa-download"></i> The fa-lg will make the icon a bit larger, and is not required. Now, instead of a "download" link, you'll see the icon rendered in each row. Clicking on the icon will download the corresponding file. However, when you hover over the icon, instead of getting the standard text, it displays this: Clearly not optimal, and very uninformative. Let's fix this with a quick Dynamic Action. I placed mine on the global page, as this application has several places where it can download files. You can do the same

Universal Theme Face Lift

I'm a huge fan of APEX's new Universal Theme, and have been working quite a bit with it.  One of the coolest features is how easy it is to change the colors.  You don't even need to be good at design - just click Theme Roller, and spin all the things! However, as much as you change the colors, the look and feel still largely looks the same, since the base font is unchanged. So let's change it up! More importantly, let's change it up without making any changes to the Universal Theme itself, so that when we upgrade to APEX 5.1, our changes will be preserved. First, head on over to Google Fonts ( https://www.google.com/fonts ) and pick a font to use as your new base font.  It doesn't really matter which one you use.  For this example, I’m going to use Montserrat.  Once you've chosen which font to use, click on the Quick Use icon.  This will render a page with a number of different options as to how to include the font in your application. Select which st

Drop It Like It's Not

I just ran the following script: -- TABLES FOR x IN (SELECT table_name FROM user_tables) LOOP   EXECUTE IMMEDIATE('DROP TABLE ' || x.table_name || ' CASCADE CONSTRAINTS'); END LOOP; -- SEQUENCES FOR x IN (SELECT sequence_name FROM user_sequences) LOOP   EXECUTE IMMEDIATE ('DROP SEQUENCE ' || x.sequence_name); END LOOP; -- VIEWS FOR x IN (SELECT view_name FROM user_views) LOOP   EXECUTE IMMEDIATE ('DROP VIEW ' || x.view_name); END LOOP; Basically, drop all tables, views and sequences.  It worked great, cleaning out those objects in my schema without touching any packages, producers or functions.  The was just one problem:  I ran it in the wrong schema. Maybe I didn't have enough coffee, or maybe I just wasn't paying attention, but I essentially wiped out a schema that I really would rather not have.  But I didn't even flinch, and here's why. All tables & views were safely stored in my data model.  All sequence