Oracle Apex: step by step approach to creating radio buttons in interactive report

tinlin28 picture tinlin28 · Feb 19, 2015 · Viewed 15.1k times · Source

Is there a good visual tutorial that takes through the various steps on how to create radio buttons in Apex 4.2? This tutorial Creating a Form in APEX to set Variables in a Query for an Interactive Report helped me in creating forms and I’m looking for a similar one.

Within my application, I would like to add a radio button to each row of my interactive report which when selected would take the user to another report combining different tables?

Any advice is much appreciated.

Thanks

Answer

Tony Andrews picture Tony Andrews · Feb 23, 2015

You could either use a column link to select the record and navigate to another page, or a radio button and a page button/link to do it. I'll demonstrate both using a simple report on the DEPT table.

Method 1: radio button

For the radio button we can add an additional column to the report using the apex_item.radiogroup function to create a radio button whose value is the DEPTNO:

Report SQL statement

By default, the HTML of the radiogroup will be escaped for security reasons, which is not what you want but illustrates what it is doing quite nicely:

Report

We can fix that by changing the column property to "Standard Report Column":

Changing column type

Now we see:

Report after fix

Clicking on the radio button on any row selects it and deselects the buttons on other rows.

To navigate to another page with the selected row we need a button to submit the page with a special request:

enter image description here

enter image description here

When clicked, that button will submit the page with a Request value of "SELECT" (the button name I chose). So we can write an on-submit page process to fire when the request is "SELECT", find out which radio button has been selected (if any) and save the selected DEPTNO to a hidden item called say P34_DEPTNO. We find out which button by looking at the APEX array apex_application.g_f01 which we chose by passing 1 as the first parameter to apex_item.radiogroup:

if apex_application.g_f01.count > 0 then
   -- Array has been populated i.e. user chose a value
   :p34_deptno := apex_application.g_f01(1);
else 
   -- Array has not been populated i.e. user did not choose a value
   :p34_deptno := null;
end if;

Then we can define a branch that navigates to the new page if (a) request = 'SELECT' and (b) P34_DEPTNO is not null.

enter image description here

And that's it. Quite a lot of work, but if that's the requirement that will do it.

Method 2: column link

The simpler way is to dispense with the radio buttons and just make one of the report columns into a link:

enter image description here

This turns the column (I chose DNAME) into a link that navigates to the new page taking the selected DEPTNO value with it:

enter image description here

That's it! No hidden item, no button, no page process, no branch...