This discussion is archived
5 Replies Latest reply: Jun 4, 2011 11:54 AM by Mindmap RSS

color the data in a column based on the value.

Mindmap Pro
Currently Being Moderated
Hi guys,

I use APEX 4.0.2

I am trying to change the color of the "calling_date" column so it would be blue when it is equal to sysdate. I typed this code in the Region Source of the interactive report.
 case
   when calling_date = sysdate then '<span style="color: #3399FF;">' || to_char(calling_date) || '</span>'
   else to_char(calling_date)
end CALLING_DATE 
AND then I changed the "Display Text AS" of the column to " Standard Report Column".

But the color would not change!!!!!!

Regards,

Edited by: Fateh on Jun 2, 2011 12:38 PM
  • 1. Re: color the data in a column based on the value.
    TexasApexDeveloper Guru
    Currently Being Moderated
    See if this blog entry helps: http://tylermuth.wordpress.com/2007/12/01/conditional-column-formatting-in-apex/

    Thank you,

    Tony Miller
    Webster, TX

    While it is true that technology waits for no man; stupidity will always stop to take on new passengers.

    If this question is answered, please mark the thread as closed and assign points where earned..
  • 2. Re: color the data in a column based on the value.
    fac586 Guru
    Currently Being Moderated
    Assuming <tt>calling_date</tt> is a <tt>DATE</tt> column, then both it and <tt>sysdate</tt> work to a granularity of a second, meaning that <tt>calling_date = sysdate</tt> will only be true when their values are exact to the second. It is likely this is not your intention.

    To what granularity is <tt>calling_date</tt> stored? Do the comparison with <tt>sysdate</tt> calling_datetruncated/rounded to the same precision as <tt>calling_date</tt>, e.g. if <tt>calling_date</tt> is stored without a time component, truncate to the day:
    case
       when calling_date = trunc(sysdate, 'DD') then...
    ...
    And if <tt>calling_date</tt> is not a <tt>DATE</tt> (or <tt>TIMESTAMP</tt>) column, then the design is totally wrong...
  • 3. Re: color the data in a column based on the value.
    Mindmap Pro
    Currently Being Moderated
    Hi guys,

    Thanks,
    I applied this one, but it gave me colored date as a char which I cannot sort according to.
    case
       when trunc (calling_date,'DD') =  trunc(sysdate,'DD') then
     '<span style="color: #3399FF;">' || to_char(calling_date) || '</span>'
       else to_char(calling_date) 
    If I remove "TO_Char", I get this error:

    inconsistent datatypes: expected CHAR got DATE

    Tony Miller, Thanks. I followed the instructions on your link, but I got the same error:

    inconsistent datatypes: expected CHAR got DATE

    Please help,
    Regards

    Edited by: Fateh on Jun 3, 2011 9:10 AM

    Edited by: Fateh on Jun 3, 2011 9:13 AM
  • 4. Re: color the data in a column based on the value.
    fac586 Guru
    Currently Being Moderated
    >
    I applied this one, but it gave me colored date as a char which I cannot sort according to.
    case
       when trunc (calling_date,'DD') =  trunc(sysdate,'DD') then
     '<span style="color: #3399FF;">' || to_char(calling_date) || '</span>'
       else to_char(calling_date)
    If I remove "TO_Char", I get this error:

    inconsistent datatypes: expected CHAR got DATE

    Tony Miller, Thanks. I followed the instructions on your link, but I got the same error:

    inconsistent datatypes: expected CHAR got DATE
    >

    Tyler's method uses *2 columns* in a standard report:
    select
             calling_date
           , case
               when trunc (calling_date,'DD') =  trunc(sysdate,'DD') then '#3399FF'
               else 'inherit'
             end color
    ...
    then combines them using an HTML Expression:
    <span style="color: #COLOR#;">#CALLING_DATE#</span>
    This is not available in an interactive report (not sure if that information was made clear in the OP?)

    In the IR, generate an HTML comment on the leading edge of the column that provides the required sort order using character semantics:
    select
    ...         
           , case
               when trunc(calling_date,'DD') =  trunc(sysdate,'DD')
               then
                 '<!-- ' || to_char(calling_date, 'YYYYMMDD') || ' --><span style="color: #3399FF;">' || to_char(calling_date) || '</span>'
               else
                 '<!-- ' || to_char(calling_date, 'YYYYMMDD') || ' --><span>' || to_char(calling_date) || '</span>'
             end calling_date
    ...
  • 5. Re: color the data in a column based on the value.
    Mindmap Pro
    Currently Being Moderated
    Thanks Fac,

    your help is highly appreciated.

    Regards,
    Fateh

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points