Oracle APEX - Conditionally Changing Text Color in a cell on an Interactive Report based on Contained Value?

允我心安 提交于 2019-12-04 13:47:57

Example with hiredate on emp: i'm about to colour the cells that are > 11000. (sysdate-hiredate ranges from about 10k to 12k). You could use a field you calculate in the query, or one you filled in through some procedure, doesn't matter :)

select empno, ename, job, mgr, hiredate, sal, comm, deptno, 
       trunc((trunc(sysdate)-hiredate)) to_colour_or_not 
  from emp

You will need 2 dynamic actions to colour rows in reports: an onload action, and an after refresh. If you skip the after refresh, rows won't be coloured after for example pagination, due to partial page refreshing.

Dynamic action one: After refresh on the region:

True action:

$("td[headers='TO_COLOUR_OR_NOT']").each(function(){
alert($(this).text());
   if(parseInt($(this).text()) > 11000){
      $(this).css({"background-color":"red"});
   };
});

Example of using one column as a condition to colour another column. Always be carefull with what you test and what you test it for! For example, the hiredate column is a date, be sure to treat it as such if necessary! Further caution too: if your date format is set as DD-MON-YYYY, then you'd have to do the mapping for month to number (JAN = 1, DEC = 12)! Maybe it is an option to change the date format for this column even...

$("td[headers='HIREDATE']").each(function(){
   var i_date = $(this).text();
   //date format = MM/DD/YYYY
   //be carefull with date formats. 
   //in my case, i know my date format and know it won't change
   //my code is far from a complete parse of possible date values!
   var dMonth = i_date.substring(0, 2),
       dDay = i_date.substring(3, 5),
       dYear = i_date.substring(6);    
   var d = new Date(dYear, dMonth, dDay, 0, 0, 0, 0);

   if(d.getFullYear() <= 1981){
      //we are looping over TD elements. I want to colour the 
      //column ENAME in red when the condition is true for this row.
      //so, $(this) = TD element we loop with. parent = TR element,
      //then back to the children of the row
      $(this).parent().children("td[headers='ENAME']").css({"background-color":"red"});
   };
});

The second dynamic action: on load

As true action, use the same code as the true action for the refresh.

With the JS you can do whatever you want: you just need to know which cells you wish to paint. Use the [headers=''] to target the cells you'd like (jquery selectors). Instead of the css(), you can use addClass for example, if that is more what you'd like.

Do mind: IRs come with built-in mouseover actions. This causes your painted cells not to show in their colour when there is a mouseover action. If you don't want this, you'd need another dynamic action for the mouseover/mouseleave events, and target those cells necessary.

As for scheduled jobs: check out DBMS_JOBS.

In an Interactive Report, you also can define REPORTS ( with HIGHLIGHTS), which will do the trick for you.

Choose button ACTIONS, Then FORMAT (on Pop-up) and the HIGHLIGHT

In HighLight you can give a Name, Type (Row or Cell), Background and Text Colour, and the COLUMN on which you want an OPERATOR and an EXPRESSION. You Apply the Highlight (Make Several Highlights /other-name when you need more than one colour-highlight depending on your EXPRESSION-s). Together with the most important Filters then SAVE it as a Report (First Primary).

After having defined the Primary Report you can take this as the basis-report. Make some other Reports (and save them) with other filters, but with the same Highlights as the Primary Report).

Have FUN with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!