1
votes

I am trying to fetch all the selected records from the interactive grid in Oracle APEX by writing the below piece of code. I have also declared #myStaticIgId as the static Id of my report.

        var record, USER_NAME;
        var x = '';

        var l_role = $v("P2_ROLE");
        var l_justification = $v("P2_JUSTIFICATION");
        var l_date = $v("P2_DATE");

        //Identify the particular interactive grid
        var ig$     = apex.region("myStaticIgId").widget();

        //Fetch the model for the interactive grid
        var grid    = ig$.interactiveGrid("getViews","grid");

        //Fetch the model for the interactive grid
        var model   = ig$.interactiveGrid("getViews","grid").model;



        //Fetch selected records
        var selectedRecords = apex.region("myStaticIgId").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
         alert(selectedRecords.length);

        //Loop through selected records 
        for (idx=0; idx < selectedRecords.length; idx++) {
            //Get the record
            record = model.getRecord(selectedRecords[idx][0]);

             alert(record);

            //Get the current value for USER_NAME
             USER_NAME  = model.getValue(record,"USER_NAME");
            //  USER_NAME  = 'Abha';

            alert('submit 2');


         }

The alert statement that I have written for returning the record value, returns NULL to me.

Can you please suggest, what needs to be done so as to get the proper record value in record variable.

Regards, Abha

3

3 Answers

0
votes

I tested your code (with some changes) here and works.

1 - Define the region ID of your Interactive Grid. enter image description here

2 - Go to chrome -> open console (press F12) -> try this code:

var gridID = "orders";
var ig$ = apex.region(gridID).widget();
var grid = ig$.interactiveGrid("getViews","grid");
var model   = ig$.interactiveGrid("getViews","grid").model;
var selectedRecords = grid.getSelectedRecords();

for (idx = 0; idx < selectedRecords.length; idx++) {
    record = model.getRecord(selectedRecords[idx][0]);
    console.log(record);
    console.log(model.getValue(record,"USER_NAME"));
}
0
votes

Finally, I got it working. the issue was the ordering of the primary key column. The primary key column should be the first column in the list after "APEX$ROW_SELECTOR" and "APEX$ROW_ACTION".

My column "ASSIGNMENT_NUMBER" with the primary key was not the first column while column "USER_NAME" was the first column in the REgions. Hence it was working for USER_NAME and not for "ASSIGNMENT_NUMBER". After changing the order of this column as first column, It worked.

enter image description here

Hope this also helps somebody!

0
votes

I am also having similar issue. Flag is "Selected List"(Yes/No). I am trying to change Flag value from "No" to "Yes" for selected Rows, However value is not getting changed. I am using below code.

function changeFlag(){
var isVerified;
var ig$     = apex.region("New").widget();
var grid    = ig$.interactiveGrid("getViews","grid");
var model   = ig$.interactiveGrid("getViews","grid").model;
var selectedRecords = apex.region("New").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
for (idx=0; idx < selectedRecords.length; idx++) {
    record = model.getRecord(selectedRecords[idx][0]);
 console.log(record);
    isVerified  = model.getValue(record,"FLAG");
    console.log(isVerified);
    if (isVerified === 'N') {
        model.setValue(record,"FLAG", 'Y');
    }  
}
}

Sample application is available in this link I am not understanding where i made issue.

Actual issue is Update the flag for bulk records using IG. I am trying to change the value to "Yes" and then will save the records. I am stuck because of this issue.