Jeff Holoman's Blog

Using images in APEX Interactive Reports

Posted by jholoman on March 9, 2012

With all of the features of interactive reports, sometimes the data itself could use a little UI improvement.

For example, if a user is scanning this report, it can be difficult to determine quickly if the product is available or not.

Adding in visual elements to the report will improve the overall UX.

In order to implement this, the markup is in the SQL itself:

select
product_id as product_id,
product_name as product_name,
product_description as product_description,
category as category,
list_price as list_price,
decode(product_avail,'Y','<img src=&chk_y.></img>','<img src=&chk_n.></img>') product_avail2
from demo_product_info
where product_name is not null

Where CHK_Y and CHK_N are setup as substitution variables:

So far so good..except when we start adding filters to the interactive report:

Yuck. It would be much nicer if we could just display the image in the filter, the same way it’s shown in the drop-down:

APEX escapes the actual value to display in the filter region, a check in the page source or in firebug reveals that the above looks like

In order for the image to display properly, we need to unescape the ‘<‘ and ‘>’ characters with the regular characters and reset the link’s HTML to use this value.

We can create a dynamic action (on Page 0, so it would work for all IR’s in the application) to help us fix this issue.

// Find the links with images in the filter
$('#apexir_CONTROL_PANEL a[title*="Edit"]:contains("img")').each(function(i,o) {
// Use the text from the <a> and remove the single quotes
var a = $(o).text().replace(/'/g,"");
// modify the original <a> tag to have the new html
$(o).html(a);
});

apexir_CONTROL_PANEL is the div that contains the filters for the interactive report. We look for any links with a title like ‘%Edit%’ that contains the word ‘img’. We then loop through those elements. Here is where it’s kind of interesting. If we use the html method in jQuery, the markup would render like this:

Using the .text() method instead returns the un-escaped html:

Next we take this text value and replace(remove really) the single quotes just before and after the img tag, and then use this value to reset the html so that the browser renders it properly.

Simple and effective:

This solution works just fine for the online or html version of reports..but admittedly hits a snag when the user tries to download  the report to csv. The tags will still be in the downloaded data.

I haven’t found a simple and elegant solution for this problem as of yet. Let me know if you have.

Link to Demo

Advertisements

2 Responses to “Using images in APEX Interactive Reports”

  1. Jari Laine said

    Hi,

    Thanks for great post.
    This my solution might be alternative when you need export CSV
    http://dbswh.webhop.net/dbswh/f?p=BLOG:READ:0::::ARTICLE:2435800346061881

    Regards,
    Jari

    • jholoman said

      Jari,

      I really like your approach. Very simple and effective. I struggled a bit with the download part, and your approach now seems so obvious 🙂

      Thanks!

      Jeff

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: