Search This Blog

About Me

My photo
Blog Written By Dr. Digvijaysinh D Virpura

Friday, May 1, 2020

Display Dynamic TextField in APEX based on Table Columns.(APEX_ITEM.TEXT)

This blog will demonstrate steps to display TextField dynamically based on Table Columns in Classic Report and insert data into database.

Oracle APEX has a large collection of API in which APEX_ITEM.TEXT is used in this example while if you want to explore in detail just click on following link.
https://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_item.htm#AEAPI192

Step1: Create a Classic Report based on SQL Query. In this demo i have used a Emp table. So my query look like as follows.

    select EMP.EMPNO as EMPNO,
              EMP.ENAME as ENAME
    from EMP EMP
and Result will look like as shown in following figure.

Now If we need to display a textbox against each employee name we need to add one dynamic APEX_ITEM.Text. So now our query will change as follows.

select  EMP.ENAME as ENAME,
   APEX_ITEM.TEXT(01,null,NULL,2,NULL,'Emp_Salary') AS Salary,
   APEX_ITEM.HIDDEN(02,EMP.EMPNO,1)as PK
 from EMP EMP
In above example APEX_ITEM_TEXT has given 01 as name which we will use while inserting data and Another Column APEX_ITEM_HIDDEN to get PK which will be kept as hidden.
If we run now then result would be shown as :



To get the Text_Field we need to change one setting.
Step 2: Select the column Salary which we have created dynamically.
Under security tab select NO to Escape special character.





If you run the report you will get it with TextField

Now we need to insert all the records which is entered by user.
Step 3: Now create one Button under a region.

Step 4: Now create one process which needs to be run on click event of a Button which we have created.            
DECLARE
TEMP_EMPNAME varchar2(20);
BEGIN
       FOR I IN 1..HTMLDB_APPLICATION.G_F01.COUNT
  LOOP
            insert into YTC_EMP(          EMPID,          EMP_NAME,          SALARY)
values(YTC_EMP_SEQ.nextval,
      HTMLDB_APPLICATION.G_F02(I),
     HTMLDB_APPLICATION.G_F01(I)
    );
  END LOOP;
 END;

In Above code HTMLDB_APPLICATION.GF02 represents EMP_NAME and G_F01 represents Salary.
If you execute the above code then you can add multiple values at the same time.
 


For Details Watch Video.


 

 

 

Have a Happy Learning

Regards
Digvijaysinh Virpura

 

1 comment:

  1. Can we have when press enter navigates to next field value of Salary ? Please help

    ReplyDelete