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!

Interactive grid- Editable: Save , Ajax Call back and Refresh

Srini-SJun 4 2020 — edited Jun 8 2020

I have an interactive grid that is editable. Data is based on a custom table that stores data temporarily, user can make changes and should be validated through few checks before sending this data to another table that is basically the main table. I make some changes and then click on a button that calls a javascript code. JavaScript basically validates the data that includes ajax callback as well. If the validations processed through the ajax call back code goes well, the data is 'Validated'. I have some problems.

- Though the grid  has a save button, user may still go to that 'validate'  button before saving the changes in the grid. So, I would like to save the data before actually initiating the validations, because validations should be done on the user updated values, not on what is already saved in temporary table. So I added a save in the processing function before calling the validations. However, this does not seem to be working properly.

- After the validations are carried out , (the process is basically making few changes to the data in the temporary table), I would like to refresh the data in the grid with whatever changes the process made to that data during validations. So, I added a refresh grid as well in the function.

Overall, these are not happening in a sequence and that seems to be the issue. I never see an updated data after processing automatically. Whenever I click refresh rows I can see it though.

Herewith I am posting the code.

async function modelProcess(model) {
   var recCount = model.getTotalRecords();
   var cnt =0;
   model.forEach(async function(r) {
      var recordId = model.getValue(r,recIdColumn);
      await recordAjaxProcess(recordId);
      cnt=cnt+1;
      display1('record # processed is :'+cnt); // function to log the values in the console
      if(cnt==recCount){        
         display1('Last record reached!!!!! :');
         return 'ajaxcallback done for all';
         }
      }
   );
   }

async function validateGridComplete (gridId,recIdColumn) {
   var lSpinner$ = apex.util.showSpinner( $( "#"+gridId ) );
   var status= await save(gridId);
   display1('Save status is :'+status);
   var model = apex.region(gridId).widget().interactiveGrid('getViews','grid').model;
   var status = await modelProcess(model);
   display1('await modelProcess- done. status is '+status);
   model.fetchAll( function( sts ) {
    if ( sts.done ) {
        display1('refreshed all the records again after !!!');
        }
      }
                 );
   lSpinner$.remove();      
   apex.message.showPageSuccess( 'Validation of all the rows is completed' );
   apex.message.clearErrors();
   return 1;
}

async function save(gridId){

       apex.region(gridId).widget().interactiveGrid("getActions").invoke("save");

       return 'Saved';

    }

async function recordAjaxProcess(rec) { 
   //console.log('Calling the Validate ajax process for the record id : '+ rec);
   return apex.server.process(
      "VALIDATE_RECORD",
      {
         X01 : rec
         },
      {
         success: function(p) {
            var sentrecId =p.sent_rec_id;
            var retrecId = p.ret_rec_id;
            var status  =p.status;
            //return 'recordAjaxProcess-done';
            if (status == 1) {
               apex.message.clearErrors();
               }
            else {
               apex.message.clearErrors();
               }
            }
         }
      );
   }

Comments
Post Details
Added on Jun 4 2020
1 comment
1,293 views