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"));