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.
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’
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.
future these blog posts I will explore the very powerful named column templates.