Christoph's 2 Cents

A Backup for My Brain!

Oracle Developement

Bulk Updating Interactive Grid Records

After my previous post on Updating Interactive Grid Cells, I wanted to try bulk updating IG records.

In this example I want to bulk update the salaries and commissions for the employees. I created a new button called Double Salaries. When the button is clicked, the salaries of the selected employees get doubled. The employees with no salary get a salary of 1000. Sales people will get their commission updated to 10% of their new salary.

Employees are selected by clicking the row selector checkbox of the interactive grid. The interactive grid’s static ID is emps.

The work is done by the JavaScript action of a dynamic action on the Double Salaries button:

[source language="javascript"]
var record, sal;
//Identify the particular interactive grid
var ig$     = apex.region("emps").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("emps").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");

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

    //Get the current salary and commision values
    sal  = model.getValue(record,"SAL");
    job  = model.getValue(record,"JOB");
    comm = model.getValue(record,"COMM");

    //If there is no salary, set it to 1000, else double it
    if (sal === '') {
        sal = 1000;
    } else {
        sal = sal * 2;
    }

    //Update the record with doubled salary and new commission
    model.setValue(record,"SAL", sal);


    //Set commission to 10% of salary for sales people
    if (job = 'SALESMAN') {
        comm = sal *.1;
        model.setValue(record,"COMM", comm);
    }

}
[/source]

emps_bulk

3 thoughts on “Bulk Updating Interactive Grid Records

  • Hi there you got the typo in above code @ //Fetch selected records
    var selectedRecords = apex.region”emps”).

  • Hi!

    You can do this a bit shorter like this:
    // Get Grid View
    var grid = apex.region(“emp”).widget().interactiveGrid(“getViews”).grid;

    // Get Model
    var model = grid.model;

    //Fetch selected records
    var selectedRecords = grid.getSelectedRecords();

    for (idx=0; idx < selectedRecords.length; idx++) {
    record = selectedRecords[idx];

    //Get the current salary and commision values
    sal = model.getValue(record,"SAL");
    job = model.getValue(record,"JOB");
    comm = model.getValue(record,"COMM")

    //If there is no salary, set it to 1000, else double it
    if (sal === '') {
    sal = 1000;
    } else {
    sal = sal * 2;
    }

    //Update the record with doubled salary and new commission
    model.setValue(record,"SAL", sal);

    //Set commission to 10% of salary for sales people
    if (job == 'SALESMAN') {
    comm = sal *.1;
    model.setValue(record,"COMM", comm);
    }
    }

    And if statement for SALESMAN is missing one equal sign.

Comments are closed.