Hiding HTML when downloading an Interactive Report

A common requirement is to format data for display in an Interactive Report, for example showing an icon, making part of the data a clickable link or a button, or showing it in different colours.

The problem with embedding formatting in the data for the report is that it is not only used for display in the web page; it is also used for the Download option, causing user confusion when HTML code is exposed in the generated CSV file.

If the logic for the formatting is not data-driven, the solution is to enter the HTML in the HTML Expression attribute on the report column definition. The HTML Expression is used only when displaying the data in the interactive report; the underlying column data is used for the Download. The underlying column data is also used to generate the filter list for the column (if Column Filter Type is “Default Based on Column Type”).

If the logic for the formatting is data-driven, a simple solution is to generate the HTML in an underlying column in the query. However, you don’t want this HTML appearing in the Download CSV, so what you can do is generate the HTML in an additional, hidden column in the report; then use the hidden column in the HTML Expression attribute. This works because the HTML Expression attribute is allowed to refer to any column in the query, even hidden ones.

For example, here is a query with a generated column that determines an icon to be displayed within the “job” column:

select ename,
       job,
       job
       || ' <span class="fa '
       || case when mgr is null then 'fa-gear' else 'fa-user' end
       || '"></span>' as job_html
from emp

The following column attributes are set:

  • JOB: HTML Expression = #JOB_HTML#
  • JOB_HTML: Type = Hidden Column

When the report is run, we see the icons displayed:

When the report is downloaded as CSV, the Job column is plaintext as desired:


Comments

  1. select ename,
    job,
    job
    case when mgr is null then ‘fa-gear’ else ‘fa-user’ end as job_html
    from emp

    and then in the HTML attributes
    #JOB#’

  2. Kinjan Bhavsar
    14 June 2019 - 5:00 pm

    Hi Jeff,

    I am using id column with anchor <a> tag to redirect to a page. Can you suggest what needs to be done for such a case?

    • Hi Kinjan,

      It doesn’t matter what html you’re generating, whether a span, a div, or an anchor or whatever – the concept is the same and you would put it in the HTML expression as usual.

      I hope this helps.

      Jeff

Leave a Reply

Your email address will not be published / Required fields are marked *