cssplsqloracle-apex

plsql select with conditional stateful colors


i have this query and it works well

select label,dateadded,headline,description,
case when label = 'Info' then 'blue'
     when label = 'News' then 'orange'
     when label = 'App Update' then 'red'
     end the_color

from news
where dateon <= sysdate and dateoff >= sysdate
order by dateadded desc

but is ther a way to use instaed the colors blue... the css from apex with stateful colors like: u-danger or u-danger-text

i have tryet to replace the case with:

case when label = 'Info' then 'u-info-text'
     when label = 'News' then 'u-warning-text'
     when label = 'App Update' then 'u-danger-text'
     end the_color

but its not working, seems he cannot find the css styles,

thanks for your help


Solution

  • This is an example based on Scott's EMP sample table. It uses code similar to yours; I'll paint different jobs into different colors.

    Interactive report source query:

    select ename, job, sal,
      case when job = 'CLERK' then 'u-info-text'
           when job = 'ANALYST' then 'u-warning-text'
           when job = 'MANAGER' then 'u-danger-text'
      end as the_color
    from emp
    where deptno = 20
    

    In Apex, edit JOB column's HTML Expression property (under "Column formatting" section) and set it to

    <span class="#THE_COLOR#">#JOB#</span>
    

    Basically, we're setting class to value set by the THE_COLOR column value (e.g. "u-info-text") and apply it to JOB column value (e.g. "CLERK").

    Run the page; result is

    enter image description here