Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to create a row in the interactive grid programmatically or get handle to newly created row

Ajay Saxena-OracleJul 7 2017 — edited Jul 7 2017

Hi,

I am trying to create rows in an interactive grid using the javascript API. The data for the rows is obtained from other components. The approach I am following now is to create the rows and then setting values to the columns of the newly created row. Below is the code fragment that I am trying to use to add rows. I am having trouble finding reference to the newly created row and had to use the private array _changes in the model object to get the last added row. Is there a better way to do update the newly created row or if possible create a row by passing these values beforehand

JS code

apex.region( "RESOURCE_TIME_REGION" ).widget().interactiveGrid( "getActions" ).invoke( "row-add-row" );

model = apex.region("RESOURCE_TIME_REGION").widget().interactiveGrid("getViews", "grid").model;

//rec = apex.region("RESOURCE_TIME_REGION").widget().interactiveGrid("getViews", "grid").getSelectedRecords()[0];

//array of all records

rec_ary = apex.region("RESOURCE_TIME_REGION").widget().interactiveGrid("getViews", "grid").model._changes;

rec = rec_ary[rec_ary.length - 1]["record"]

// does not work as getActiveRecordId points to the deleted record when we delete a row

//rec_id = apex.region("RESOURCE_TIME_REGION").widget().interactiveGrid("getViews", "grid").getActiveRecordId();

//rec = apex.region("RESOURCE_TIME_REGION").widget().interactiveGrid("getViews", "grid").model.getRecord(rec_id);

model.setValue(rec,"GPO_ID",$("#P50_GPO option:selected").val());

model.setValue(rec,"FINANCIAL_YEAR",$("#P50_FINANCIAL_YEAR option:selected").val());

model.setValue(rec,"RESOURCE_ID",$("#P50_USER option:selected").val());

model.setValue(rec,"QUARTER_1", $v("P50_QUARTER_1"));

model.setValue(rec,"QUARTER_2", $v("P50_QUARTER_2"));

model.setValue(rec,"QUARTER_3", $v("P50_QUARTER_3"));

model.setValue(rec,"QUARTER_4", $v("P50_QUARTER_4"));

This post has been answered by John Snyders-Oracle on Jul 7 2017
Jump to Answer

Comments

John Snyders-Oracle
Answer

Hi Ajay,

One way to do this is not use the row-add-row action but directly insert into the model.

For an IG on EMP it would look something like this:

var gridView = apex.region("emp").widget().interactiveGrid("getViews").grid;

var model = gridView.model;

var sel = gridView.getSelectedRecords();

var newId = model.insertNewRecord(null, sel[sel.length - 1]);

var rec = model.getRecord(newId);

model.setValue(rec, "ENAME", "TED");

//... more setValue calls.

model.setValue(rec, "ONLEAVE", {d:apex.item("C_ONLEAVE").displayValueFor("N"), v:"N"});

This adds after the last selected row. If you want the new row added at the beginning call insertNewRecord with no arguments.

Note the special handling for columns that have display values like switch or select list. You must also make sure that the default value for the column is something outside the normal values such as null.

This does not put the grid in to edit mode. It also will not run any DAs on column items because values are set directly on the model rather than setting page items.

The other way to handle this is to .invoke( "row-add-row" ) and then respond to the apexbeginrecordedit event. I think this has been described in the forums before in the context of how to apply more complex defaults to a newly added row.

Regards,

-John

Marked as Answer by Ajay Saxena-Oracle · Sep 27 2020
Ajay Saxena-Oracle

Thanks Dave, I wasnt able to find the model.insertNewRecord call earlier, will use it for my requirement

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 4 2017
Added on Jul 7 2017
2 comments
2,172 views