Build beautiful and interactive API documentation for ORDS

Image
In this blog post, I will show you how to quickly build beautiful and interactive API documentation for your Oracle APEX REST data sources using  swagger hub . Using APEX v23.1. I downloaded the  titanic data set  and loaded them into tables in my APEX instance, created some authorized restful services and published them using swagger hub. You can create a free account on swagger hub.   Check out my titanic swagger hub here ; Press Authorize. Username REST, password Glasgow123! I won't go through creating RESTful services and just show you the four I created that sit on top of the titanic data set; The GET is a very simple SQL query;      select * from TITANIC_DATA_SET_NEW A handy tip is to add comments, as there will appear on swagger hub, making your API self documenting; Once you have created your modules, press the Generate Swagger Doc button; This will generate an open API for you.  Copy the API and paste it into swagger hub This will generate the documentation; As mentioned b

Oracle APEX Interactive Grid colour cells based on a condition using JavaScript and CSS

In this post I will describe how to colour an Interactive Grid based on a column condition using CSS and JavaScript.  Using APEX Version 19.2.

I want to colour every column red in my IG when the value is 'No'.  


I have several IGs on my page I want to colour, so I set all my IGs that I want to colour with a CSS class of ATTENDEE_SCORE_IG in the Appearance section of the IG;




Every column I want to colour in the IG I set the CSS Class to COLOUR_YES_NO (in this example I set this in 5 columns);


I then created a Dynamic Action (DA) that contains the JavaScript that has the condition check that will colour the cells.  Because I have several IGs that are details of the master/detail relationship and these are refreshed by the user clicking on the master detail IG I have made my DA a Page Change [Interactive Grid].  If you don't need this you can set the DA on page load.


The JS which will colour every column is this;

////////////////////////////////////////////////////////////////////////////////////////////////
// This function colours IG columns that are Yes/No to red if its no and green if its yes.
//
// Currently using green (u-success) and red (u-danger) but these can be changed to
// any colour defined here;
// 
// https://apex.oracle.com/pls/apex/apex_pm/r/ut/color-and-status-modifiers
// 
// Example.  
//
// The param igClassName is the IG class name with Yes\No columns you want to colour.
//
// Set the IG class name. Appearance->CSS classes, in this example ATTENDEE_SCORES_IG.
// For all Yes/No columns you want to colour set the CSS Class of the column to COLOUR_YES_NO.
//
// colourYesNoScores('ATTENDEE_SCORES_IG');
//
////////////////////////////////////////////////////////////////////////////////////////////////
function colourYesNoScores(igClassName)
{
    $('.' + igClassName + ' ' + 'td.COLOUR_YES_NO').each(function(){
         cellData = $(this).text();
         if (cellData == 'No') {
            $(this).addClass('u-danger');
         }
         else {
            $(this).addClass('u-success');
         }       
    });
};
// colour every IG on the page that has a class of ATTENDEE_SCORES_IG
colourYesNoScores("ATTENDEE_SCORES_IG");

This will colour every IG cell with a CSS class ATTENDEE_SCORES_IG and columns CSS class of  COLOUR_YES_NO if the cell value meets the condition.

Currently, using green (u-success) and red (u-danger), these can be changed to any colour defined here;

    https://apex.oracle.com/pls/apex/apex_pm/r/ut/color-and-status-modifiers

The advantage of using CSS is that any further IGs I add to the page all I need to do is ensure that the CSS classes are set, and it will automatically colour the cells.

The JS code will be placed in my utility JS file (utlility.js) which I import into all my projects which will automatically colour all YES/NO IGs that have the CSS set.  

This gives me a standard way of colouring Yes/No columns in every project I use without having to write any code.



Comments

  1. I tried above code but it has no impact on IG. The JS function is called on PAGE_LOAD successfully but it is not updating any color.

    ReplyDelete
    Replies
    1. function colourYesNoScores(igClassName)
      {
      $('.' + igClassName + ' ' + 'td.COLOUR_YES_NO').each(function(){
      cellData = $(this).text();
      if (cellData == 'No') {
      $(this).addClass('u-danger');
      }
      else {
      $(this).addClass('u-success');
      }
      });
      };
      // colour every IG on the page that has a class of ATTENDEE_SCORES_IG
      colourYesNoScores("ATTENDEE_SCORES_IG");


      This is the JS code that you have provided. I have verified that required CSS classes has been there for IG and for required column.

      Delete

Post a Comment

Popular posts from this blog

Oracle APEX pretty checkbox item plugin

Build beautiful and interactive API documentation for ORDS