We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to use CellEditArgs event in Angular Grid

Kindly give a example of CellEditAgrs

3 Replies

RS Rajapandiyan Settu Syncfusion Team April 24, 2020 10:23 AM UTC

Hi Namita, 
  
Greetings from syncfusion support. 
  
Query : Kindly give a example of CellEditAgrs 
 
In EJ2 Grid, cellEdit is achieved by set the mode as Batch in the grid editSettings. By default double clicking the cell moves the clicked cell into edited state. Before that it triggers cellEdit event in which you can get the clicked cell element, cell value, filed name, row data, clicked row element, column modal, foreignKey details and primayKey as arguments. Please refer the below screenshot. 
 
 
 
The cancel API is used to decides the editing operation. If it is true, it prevents the editing in grid.  
 
Now the cell is moved in edited state after the cellEdit event, clicking overlay of the form or enter button saves the cell in batch mode. You can get all the batchChanges records by the method getBatchChanges(). 
 
Clicking update button saves the batchChanged records in grid. Before that it triggers beforeBatchSave (triggered before save action occurs) and actionComplete with requestType as batchSave (triggered after save action occurred). 
 
Please refer the below sample and documentation for more information.  
 
 
 
 
Please get back to us if you need further assistance on this. 
 
Regards, 
Rajapandiyan S


KP Ketan Patel October 12, 2022 03:49 PM UTC

Hi Team,

In beforebatchSave event I want to fire a POST API request and on failure I want to set e.cancel = true and on sucess I want to allow grid update to complete. Is it possible to acheive?




RS Rajapandiyan Settu Syncfusion Team October 13, 2022 02:45 PM UTC

Hi Ketan,


Thanks for contacting Syncfusion support.

Query: In beforebatchSave event I want to fire a POST API request and on failure I want to set e.cancel = true and on sucess I want to allow grid update to complete. Is it possible to acheive?


Yes, you can achieve your requirement by using a flag variable in the beforeBatchSave event. Initially, we set the flag variable as false. When you save the changes, the beforeBatchSave event will be triggered. In that event, we execute args.cancel as true if the flag variable is false and post the request to the server.


In the success event of the post, we make the flag variable as true and save the data in Grid by executing the batchSave method. Find the below code example and sample for your reference.


beforeBatchSave: https://ej2.syncfusion.com/angular/documentation/api/grid/#beforebatchsave

batchSave: https://ej2.syncfusion.com/angular/documentation/api/grid/edit/#batchsave

batchCancel: https://ej2.syncfusion.com/angular/documentation/api/grid/edit/#batchcancel

actionComplete: https://ej2.syncfusion.com/angular/documentation/api/grid/#actioncomplete

 

[app.component.ts]

export class AppComponent {

  public isReadyToSave: boolean = false; // initialize the flag variable


  beforeBatchSave(args) {

    // triggered before the save action occurred in grid

    console.log(args);

    if (!this.isReadyToSave) {

      args.cancel = true; // prevent the save action based on the flag variable

      this.grid.showSpinner();

      var ajax = new Ajax('https://ej2services.syncfusion.com/production/web-services/api/Orders','GET');

      ajax.send(); // send the post to server

      ajax.onSuccess = (data: string) => {

        this.isReadyToSave = true; // make the flag variable as true if the post is successive

        this.grid.editModule.batchSave(); // save the changes to Grid

        alert('Post successive');

      };

      ajax.onFailure = (data: string) => {

        this.grid.editModule.batchCancel();  // discard the changes

        alert('Post Failure');

      };

    }

  }

  actionComplete(args) {

    if (args.requestType == 'batchsave') {

      // triggered after saving the batch edited records in grid

      this.isReadyToSave = false;

    }

  }

}

 


In the actionComplete event (requestType as batchsave), we make the flag variable as false to perform next save operation.


Sample: https://stackblitz.com/edit/angular-7n5add?file=app.component.html,app.component.ts

Please get back to us if you need further assistance.


Regards,

Rajapandiyan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Loader.
Live Chat Icon For mobile
Up arrow icon