Using Conditions with Column Templates

Report templates can be a powerful feature for altering the way a report looks. They fall under two main Template Types: Generic Columns and Named Columns. This blog post covers Generic Columns and the ability we have to specify a condition for these columns.

With a Generic Column template, we are able to specify how an individual cell will display. We have four template definition placeholders. APEX will look at “Column Template 1” first and if there’s no condition or if the condition is met, it will use it. Otherwise, it moves on to “Column Template 2” and so on.

We’ll use the following SQL for a Standard Classic report.

Our goal is to highlight the rows for products that are not available any more (PRODUCT_AVAIL=’N’)
We start by making a copy of the current report template. You can see which one you’re using in the Report Attributes. I also like to see which one I use by opening the templates portion of the tree under the Shared Components column on the page designer.

all templatesChose a new name for your template:

Copy TemplateAssign this new template to the report (also under Report Attributes).

Assign template in Report Attributes

Assign template in Report Attributes

At this point, our report will still look identical. Lets get started with the changes.
Edit the template and add a new class, for example “highlight” to the column template. Also, change the Column Template Condition to “Used Based on PL/SQL Expression” with :PRODUCT_AVAIL = ‘N’

Edit Report Template

Edit Report Template

Notice how we’re able to use the name of our columns as bind values in the condition. This change that makes this template specific to a report that includes the mentioned columns. This is why I recommend you use a name that ties the template to the report in some way. Also notice how we add the class highlight and we don’t replace or change the other classes (like “data” and “rptCol”. This is needed so the look and feel of the report is not affected.

Then, if your template is alternating colors, “Column Template 2” should contain the template for rows with a class that will change the background. Usually a class name like dataalt.

 

The Column Template 2 Condition can be set to “Use for Odd Numbered Rows”.

Finally, we need one last template with no condition as a catch all. It will be used when the other two conditions are not met.

Here’s the CSS that we want to include on the page for our highlight class:

Here’s the end result. Or visit a quick demo here.

Report with highlighted rows via Conditions.

Report with highlighted rows via Conditions.

In future these blog posts I will explore the very powerful named column templates.

Hi, I'm Jorge Rimblas. Father, husband, photographer, Oraclenerd, Oracle APEX expert, Oracle ACE, coffee lover, car guy, gadget addict, etc... I'm a Senior APEX Consultant with Insum Solutions, a consulting firm specialized in Oracle databases and the APEX development tool. I have worked with Oracle since 1995 and done eBusiness Suite implementations and customizations. Nowadays I specialize almost exclusively in Oracle APEX.

3 comments on “Using Conditions with Column Templates
  1. Hi Jorge,

    nice work! Do you think it is also possible to highlight certain columns only (instead of the whole row)?

    Cheers
    Jeroen

    • Hi Jeroen,

      In order to highlight certain columns you probably need a Named Column template or a Dynamic Action/JavaScript solution. It would depend on the requirement. For example, if it’s always cells on the same column(s) that need highlighting then the Named Column template will work great. If the approach is more complex it may require JS.

      Hey, feel free to elaborate.

      Thanks
      -Jorge

      • Thanks for your reply Jorge. I cannot use a named column template because my report has to be dynamic (i.e. the number of columns is dynamic, not fixed). Will update here if I can get it done.

        Cheers
        Jeroen

I love comments, write me a line