Hi Albert,
Thanks for contacting Syncfusion support.
By default in EJ2 Grid the actionBegin event is the synchronous function, so we cannot handle any asynchronous function and you cannot perform asynchronous operation in the actionBegin event.
Please share the below details that will be helpful for us to check the feasibility of your requirement and provide a better solution based on that.
1) What action do you need to perform in the Grid before saving the edited record.
2) Do you need to avoid the save operation until the data returned from the backened?
3) Share us your exact requirement scenario with detailed description.
Let us know if you have any concerns.Regards,Shalini M.
|
export class FetchDataComponent {
public data: any;
public editSettings: any;
public toolbar: any;
public flag: boolean = true;
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
this.data = new DataManager({
url: 'Home/UrlDatasource',
updateUrl: 'Home/Update',
insertUrl: 'Home/Insert',
removeUrl: 'Home/Delete',
adaptor: new UrlAdaptor
});
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' };
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
}
actionBegin(args: any) {
var parse: any;
var getFlag = this;
if (args.requestType == "save" && this.flag) {
args.cancel = true; //prevent the default save action
var row = JSON.stringify({ rowData: [{ OrderID: args.data.OrderID }] });
var ajaxObj = new Ajax();
ajaxObj.type = 'POST';
(ajaxObj as any).contentType = 'application/json';
ajaxObj.url = '/Home/SelectRecord';
ajaxObj.data = row;
ajaxObj.send().then(function (value: any) {
getFlag.flag = false;
parse = JSON.parse(value);//get the returned value here before saving the record and you can perform your calculation here
var grid = (document.getElementById('Grid') as any).ej2_instances[0];
grid.endEdit(); //call the endEdit() to save the modified record. It will trigger the Server side Update() method
});
}
}
actionComplete(args: any) {
if (args.requestType == "save" && args.action == "edit") {
this.flag = true;
}
}
}
|