Oracle Apex - Row Selector - Delete Selected Multiple Rows

To delete multiple values, we can use the amazing Row Selector type Item. we can use the following javascript and PLSQL :

 In the IG make any column as Row Selector. e.g.


Create Dynamic Action like below. e.g.


Add the following JavaScript code on true action after adding two hidden Text Item like :

P18_ID and
P18_CUR_ID

P18_ID           --------->   
SET VALUES OF SELECTED ID
P18_CUR_ID -------->    SET VALUE OF CURRENT ID.

Javascript code on True Action :

var i, i_empids = ":", i_empid,

model = this.data.model;

for ( i = 0; i < this.data.selectedRecords.length; i++ ) {

       i_empid = model.getValue( this.data.selectedRecords[i], "CATEGORY_ID");

       i_empids += model.getValue( this.data.selectedRecords[i], "CATEGORY_ID") + ":";

}

apex.item( "P18_ID" ).setValue (i_empids);

apex.item( "P18_CUR_ID" ).setValue (i_empid);


Your page will show like the below picture :


When I click Bangla Version and English Version The JavaScript dynamic Action will set value:


According to value set at ID column which will be hidden later we write a process to delete data of selected IDs and delete through a button DEL. :

BEGIN
  FOR I IN 
  (SELECT t.Column_value AS id
   FROM TABLE(Apex_String.Split(RTRIM(LTRIM(:P18_ID, ':'), ':'),
                                   ':')) t) LOOP
   DELETE FROM CATEGORIES WHERE CATEGORY_ID=I.ID AND SCHOOL=F_SCHOOL(:APP_USER);
  END LOOP;
END;

Summary :

Dynamic Action :

Event : Selection Change [Interactive Grid]
Selection Type : Region
Region : Region Name

Javascript Code :

var i, i_empids = ":", i_empid,
model = this.data.model;
for ( i = 0; i < this.data.selectedRecords.length; i++ ) {
    i_empid = model.getValue( this.data.selectedRecords[i], "CATEGORY_ID");
    i_empids += model.getValue( this.data.selectedRecords[i], "CATEGORY_ID") + ":";    
}
apex.item( "P18_ID" ).setValue (i_empids);
apex.item( "P18_CUR_ID" ).setValue (i_empid);


Delete (Process) :

BEGIN
  FOR I IN 
  (SELECT t.Column_value AS id
   FROM TABLE(Apex_String.Split(RTRIM(LTRIM(:P18_ID, ':'), ':'),
                                   ':')) t) LOOP
   DELETE FROM CATEGORIES WHERE CATEGORY_ID=I.ID AND SCHOOL=F_SCHOOL(:APP_USER);
  END LOOP;
END;


P18_ID   -----> HOLDS SELECTED CATEGORY ID WITH COLLON SEPARATOR. (selected IDs).




























Muhammad Abdullah Al Noor

Muhammad Abdullah Al Noor, An Oracle Apex Consultants and founder of Noors Technology (www.noorstech.com). Core Expertise : Database Administration, Oracle Forms and Reports Development, Oracle Apex Application Designer and Development, Linux Professional etc. Also the owner of TrainerBD Training and OraDemy E-Learning. WhatsApp +8801790721177

Post a Comment

Previous Post Next Post