Coding Duchess
Coding Duchess

Reputation: 6909

How to programmatically add a record to an APEX Interactive Grid?

I need to add a new record to one of the interactive grids on my page via javascript code.

I know how to get an record from the grid:

 var model = ig$.interactiveGrid("getViews","grid").model;
 var record = model.getRecord(rowID);

But how do I add a record? Is there a function for that?

What I am trying to do is get selected rows from one grid and insert it into the underlying table in another grid. I got my javascript code to grab the records selected in grid1 and loop through them. Now I am getting the model of the grid2 and want to insert the records from grid1 into grid2

Upvotes: 2

Views: 7056

Answers (1)

romeuBraga
romeuBraga

Reputation: 2165

Try to insert a new record and immediately update the values.

var widget      = apex.region('staticIdOfIG').widget();
var grid        = widget.interactiveGrid('getViews','grid');  
var model       = grid.model; 

//insert new record on a model
var myNewRecordId = model.insertNewRecord();

//get the new record
var myNewRecord = model.getRecord(myNewRecordId);

//update record values
model.setValue(myNewRecord, 'NAME_OF_COLUMN1', 'value1');
model.setValue(myNewRecord, 'NAME_OF_COLUMN2', 'value2');

Example: https://apex.oracle.com/pls/apex/f?p=145797:8

*Click on button "INSERT ROW WITH VALUES"

Workspace: stackquestions
login: test
pwd: test
page: 8

Upvotes: 4

Related Questions