Oracle Apex - Add Interactive Grid into a Form

In this Oracle Apex tutorial, I will teach you how to add an Interactive Grid into a Form manually to make it behave like master-detail form.

I have an existing form on the Department table which is having two fields, DEPTNO and DNAME. The requirement is to add a detail section below the form to show all employees under the current department, and the user can add/edit employees under that department.

So, in this case, we should add an Interactive Grid into the form. Follow these steps:

Add an Interactive Grid into a Form Manually in Oracle Apex

  1. Open the form in Oracle Apex designer in which you want to add an Interactive grid. To demonstrate this, I am using the Department form, which is being called by the Department Report.
  2. Then right-click on the Content Body and click on the Create Region and set the following properties highlighted in the image below:

Interactive Grid Report setting step - 1

  1. I added the following query into the above SQL Query section:
Select ROWID, empno as employee_no, ename as employee_name, hiredate, deptno as dept, sal as salary from emp where deptno = :p5_deptno

You can see above that I added the P5_DEPTNO in the Page Items to Submit because I am using this item in the query. So you should add all the items you are using in the query to Page Items to Submit.

  1. It is better to use ROWID as Primary Key instead of actual Primary Keys for the Forms and Reports in Oracle Apex because it is faster to fetch and update records using the ROWID for faster performance, also helps to assign default values to the columns we are linking to the master table. In this example, we are linking DEPTNO from the EMP table to the DEPT table. So now click on the DEPT field in the Employees region and set the following properties:

DEPT column settings

The above properties I have set because when the user clicks on the Add Row button in the Interactive GRID, it will take the default DEPTNO from the Master table DEPT.

  1. Now click on the Attribute section of this Interactive Grid and set the properties shown below:

Interactive Grid setting step - 5

Now when you open the Department form from the Department Report for a specific department number, you will have the following output:

Oracle Apex Form with Interactive Grid Example.

See also:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

10 Comments

    • Create a dynamic action on before submit event to execute JavaScript code. Then follow these steps:

      Specify a static ID to your IG, for example: igemp.

      Create a hidden page item, for example, px_youritem.

      Then add the following JavaScript code into the DA you created to set the page item value to 1 if records exists and to 0 if not exists.

      var model = apex.region("igemp").widget().interactiveGrid("getViews", "grid").model;
      var n_count;
      col_empno = model.getFieldKey("EMPNO");
      model.forEach(function(igrow) {
        if (igrow[col_empno].isEmpty()) {
           n_count = 0;
        } else {
          n_count = 1;
        } 
        break;
      });
      $s('Px_YOURITEM', n_count);
      

      Now in a process, you will be able to read the Px_YOURITEM item to know whether your IG is having the records or not.

    • i am trying, but it doesn't work

      1. set static ID in my IG: IGITEMDATA
      2. add new page item in IG: Px_IG_ITEM (i am not sure there is any selection in it?)
      3. Javascript in attachment file.
      4. add DA before page submit

      var model = apex.region("IGITEMDATA").widget().interactiveGrid("getViews", "grid").model;
      var n_count;
      col_IG_ITEM = model.getFieldKey("ITEM");
      model.forEach(function(igrow) {
       if (igrow[col_IG_ITEM].isEmpty()) {
         n_count = 0;
       } else {
        n_count = 1;
       } 
       break;
      });
      $s('Px_IG_ITEM', n_count);

    • Create a process to check if px_ig_item is equals to 1 or 0, then take the action accordingly.

  1. Hi Vinish,

    Do you have an example on how to create a Form with Next/Preview button to move through the records.

    Thank you,

    Varduhi

    • Also I just need separate Save for IG but also want the toolbar. How can I get this implemented.

Comments are closed.