Home » Developer & Programmer » Application Express & MOD_PLSQL » Conditionally change the colour of the text (APEX 4.0)
Conditionally change the colour of the text [message #542773] Fri, 10 February 2012 02:56 Go to next message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
Hello Smile

I've got the following table:
./fa/9828/0/
Is it possible to have either the text or the background of the <td> (or both) to display as green/red when it's Y/N respectively?

thanks

[Updated on: Fri, 10 February 2012 02:56]

Report message to a moderator

Re: Conditionally change the colour of the text [message #542776 is a reply to message #542773] Fri, 10 February 2012 03:02 Go to previous messageGo to next message
Littlefoot
Messages: 19694
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If it is an interactive report, you can set it in Actions - Format - Highlight (set a condition in there).

Or, you could try with SELECT statement itself, such as
select 
  case when ver = 'Y' then
        '<font color="red">' || milestone ||'</font>'
       else 
        '<font color="green">' || milestone ||'</font>'
  end milestone,
  ...
from ...

If you do the latter, pay attention to column's "Display As" column attribute - should be set to STANDARD REPORT COLUMN.

[Updated on: Fri, 10 February 2012 03:03]

Report message to a moderator

Re: Conditionally change the colour of the text [message #542784 is a reply to message #542776] Fri, 10 February 2012 03:25 Go to previous messageGo to next message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
Hi, I'ts not an interactive report so I tried the other way, but its returning an error:
failed to parse SQL query:
ORA-00904: "PMO": invalid identifier
Re: Conditionally change the colour of the text [message #542789 is a reply to message #542784] Fri, 10 February 2012 03:30 Go to previous messageGo to next message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
My query is now:
select 
  pm.MILESTONE_ID ||'' - ''||cp.CHECKPOINT_NAME "Milestone",
  pm.MILESTONE_DATE "Date", 
case when Ver = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 1),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 1),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "Ver", 
case when SnR = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 2),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 2),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "SnR", 
case when Som = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 3),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 3),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "Som", 
case when ITA = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 4),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 4),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "ITA", 
case when ITF = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 5),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 5),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "ITF", 
case when PMO = 'Y' then 
        '<font color="green">' ||  
        decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 6),1, 'Y', 0, 'N', 'N') ||'</font>' 
       else  
        '<font color="red">' || decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 6),1, 'Y', 0, 'N', 'N') ||'</font>' 
  end "PMO"
from PMO_MILESTONES pm,
     PMO_CHECKPOINT cp
where pm.PROJECT_ID = :P2_PROJECT_ID
  and cp.checkpoint_ID = pm.checkpoint_ID
Re: Conditionally change the colour of the text [message #542800 is a reply to message #542789] Fri, 10 February 2012 03:59 Go to previous messageGo to next message
Littlefoot
Messages: 19694
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
16 lines from bottom, you have CASE WHEN PMO = 'Y'. Is that correct?
Re: Conditionally change the colour of the text [message #542817 is a reply to message #542800] Fri, 10 February 2012 04:37 Go to previous messageGo to next message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
Wait I've been looking at my code and could I do it with the DECODE?

so something like:
decode((select pmr.IS_APPROVED   
    from PMO_MILESTONE_REVIEW pmr   
    where pmr.MILESTONE_ID = pm.MILESTONE_ID   
    and pmr.ROLE_ID = 2),1, '<font color="green">Y</font>', 
0, '<font color="red">N</font>', '<font color="red">N</font>')
Re: Conditionally change the colour of the text [message #542818 is a reply to message #542817] Fri, 10 February 2012 04:46 Go to previous messageGo to next message
Littlefoot
Messages: 19694
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I don't know - did you try it? What happened? Did you paid attention to column's "Display As" column attribute - should be set to STANDARD REPORT COLUMN?
Re: Conditionally change the colour of the text [message #542824 is a reply to message #542817] Fri, 10 February 2012 05:05 Go to previous messageGo to next message
c_stenersen
Messages: 254
Registered: August 2007
Senior Member
Yes you could do it with decode. Or you could go to report attributes -> column attributes. Then you could use the settings below, and it should work.

./fa/9830/0/

Edit: Oh sorry, I see you wanted Y as green and N as red. Then you just use N as the highlight
  • Attachment: YN.jpg
    (Size: 11.64KB, Downloaded 176 times)

[Updated on: Fri, 10 February 2012 05:07]

Report message to a moderator

Re: Conditionally change the colour of the text [message #542825 is a reply to message #542818] Fri, 10 February 2012 05:09 Go to previous messageGo to next message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
Yeh I tried it, it didn't seem to work...it just ignored the <font> tag...
Might be something to do with the way its all laid out, it's a little confusing
It's described in the previous thread on the Application Express forum.

I've had to use the generic column names so in the report attributes I have 'COL01' COL02' etc. instead of the column names...but I've changed the relevant ones to Standard Report Column and nothing's happened...so I dno

It's not at all important anyway just something I thought would be kewl but I think it would be more trouble than it's worth to sort it all out at this point
Re: Conditionally change the colour of the text [message #542841 is a reply to message #542825] Fri, 10 February 2012 06:49 Go to previous messageGo to next message
c_stenersen
Messages: 254
Registered: August 2007
Senior Member
I tried it, and for me it works with setting it to standard report column. I used a span tag with a style attribute rather than a font tag however. E.g <span style="color:green"> So maybe it's ignoring the font tag since it's rather using the css defined in the template.
Re: Conditionally change the colour of the text [message #542843 is a reply to message #542841] Fri, 10 February 2012 07:05 Go to previous message
balckbandit5
Messages: 104
Registered: December 2011
Senior Member
Ok this is retarded but it turns out when I thought I was reloading the page to test the changes, I wasn't.
The part that has all the decode and font tags and stuff is in an item which the report then references. The thing is, the items were AFTER the report...so the report was doing the query with the value that was already in the session, not the one I thought I was testing.

So I've moved the items before the report and its all working now -_- *sigh*
(When I came back from lunch I reloaded the page and it was all working confused me muchly at first haha)

thanks Smile
Previous Topic: Right To Left Application
Next Topic: ORA-01008: not all variables bound
Goto Forum:
  


Current Time: Thu Oct 23 16:25:03 CDT 2014

Total time taken to generate the page: 0.08302 seconds