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
close icon

Continuing the save process after AJAX validation

I have a grid that allows inline editing and I need to check the values of one of the columns and prevent saving if there's a duplicate. I've been following the guide here to accomplish this with an AJAX request. I have been able to prevent saving by settings args.cancel = true before the request, but when it reaches this section in the success function it fails because gridobj is undefined:

     var gridobj = $('#AGrid').data('ejGrid');
     gridobj.endEdit();

I have also tried using the EJ2 code for endEdit() here:

     var gridObj = document.getElementById('Grid').ej2_instances[0];
     gridObj.endEdit();

My grid is initialized in the view with this code:

     @(Html.EJS().Grid("Grid").Toolbar(toolbarOptions).EditSettings(editSettings).ActionBegin("actionBegin").DataSource(datamanager => ....

3 Replies

PS Pavithra Subramaniyam Syncfusion Team October 8, 2019 12:07 PM UTC

Hi Taylor, 
Thanks for conducting Syncfusion support. 
We have validated your query “Continuing the save process after AJAX validation” at our end. 
By default, You can achieve your requirement using actionBegin event. Here we have to validate the required column value before saving. 
If the changed value doesn’t meet your validation state, you have to call closeEdit() method instead of endEdit(). 
closeEdit() method used to destroy the edit form. If validation throws the success, changed value will be updated in dataSource. 
Please refer to the below code example and sample. 
 
@Html.EJS().Grid("DefaultPaging").ActionBegin("ActionBeginEvent") . . . ..Render() 
 
function ActionBeginEvent(args) { 
        if (args.requestType == 'save') { 
            var gridObj = document.getElementsByClassName("e-grid")[0].ej2_instances[0]; 
            if (args.data.CustomerID.length < 5) {   // you can write validation condition here..... 
                args.cancel = true; 
                gridObj.closeEdit(); 
            } 
        } 
    } 
 
 
Still the above sample and code block don’t meet your requirement please share the below details for further updates. 
  1. Share which adaptor you are using in your application.
  2. Full code snippet
  3. Expecting output image
Regards, 
Pavithra S. 



TT Taylor Tillman October 11, 2019 03:25 PM UTC

Hi Pavithra,

Thanks, this helped. I ended up having to add the flag variable as shown in the knowledge base article I linked but I was having also having problems getting the grid object. Your method of  var gridObj = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; ended up working.


PS Pavithra Subramaniyam Syncfusion Team October 14, 2019 08:46 AM UTC

Hi Taylor, 
 
Thanks for your update. 
 
We are happy to hear that the provided information helps you. 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon