Select/De-select all rows in IG in Oracle Apex

In this article we going to see how to select and de-select all rows in IG in Dynamic action. This work is done by execute a JavaScript code in dynamic action of button click.In the end of the article I have included the demo application for your reference.

Let see step by step approach how to do it.
Step 1: Create an IG (Interactive Grid) region and paste required SQL code. For demonstration purpose I used emp table (select * from emp).

Step 2: Assign static id for that IG region. E.g emp



Step 3: make sure that IG is editable.



Step 4: Create button (name- select_all) and create a dynamic action (on click event) for that button. Create true action and you can see many action types but we going to use JavaScript. So change it’s action type as “Execute JavaScript code”.

Step 5: paste the following code for select all row in a IG.
apex.region("emp").widget().interactiveGrid("getViews", "grid").view$.grid("selectAll");
apex.message.showPageSuccess( "All Rows selected successfully." );
Step 6: Similarly for de-select all rows in a IG, create another button and create dynamic action of JavaScript action type. Paste following code.

var ig$     = apex.region("emp").widget();
var selectedRecords = apex.region("emp").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
for (idx=0; idx < selectedRecords.length; idx++) {
    ig$.interactiveGrid("getViews", ig$.interactiveGrid("getCurrentViewId")).setSelection($());
}
if (selectedRecords.length==0){
    apex.message.clearErrors();
    apex.message.showErrors( { type:       "error",
                               location:  [ "page"],
                               message:   "Please select atleast one row to de-select.",  
                               unsafe:     false
                             }
                           );
}
else    {
    apex.message.showPageSuccess( "All Rows de-selected successfully." );
}




I hope this article will help you to select and de-select the row in IG. In case if you need any clarification or suggestion, kindly leave a message in the comments box.

Tag: Oracle apex 5, Oracle Apex IG, Process Rows in IG, Select all rows in IG , De-select all the row in IG.

1 comment:

  1. Uncaught TypeError: ig$.interactiveGrid(...).setSelection is not a function

    ReplyDelete