Row Validation in Backend

HI, 

Is it possible to validate with backend sending data in json format in normal mode editing?
Which is the event I need to use to send the data and how to get the row data?


Many thanks!

5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team August 14, 2020 03:58 PM UTC

Hi Carlos, 
 
Thanks for contacting Syncfusion support. 
 
Based on your query we suspect that you are expecting the server side validation for the Grid Editing. Currently in EJ2 Grid we have support only for the client side validation, so before we proceed with your query we need to confirm the following details, 
 
1. In this forum you have selected the platform as Vue, so please confirm the framework(ASP.NET Core or MVC) that you have used for the server side? 
 
2. For databinding in Grid have you used the Syncfusion Adaptors or custom binding?  
 
Please find the documentation of Syncfusion Data Adaptors 
 
 
3. Share the complete grid rendering code.  
 
Regards, 
Prasanna Kumar N.S.V 
 



CA Carlos Alarcon August 14, 2020 04:27 PM UTC

Yes we are using vue in our frontend  which communicates to our api via json. That api was built in .net core

Since we have many rules to validate we prefer to send the entire row to the api to execute validations.

So, the idea is to send this row to backend and check this data there. But we dont know the exact method or event to make this call.

Thanks!


BS Balaji Sekar Syncfusion Team August 17, 2020 01:36 PM UTC

Hi Carlos, 
 
Thanks for your update,  
 
Before proceeding with your query, we need additional information about your requirement so, please share the below details to us that will help to validate further. 
  1. Please share the server side code definition of JSON data fetching from API.
  2. Grid rendering full code in client side.
 
Regards, 
Balaji Sekar 



CA Carlos Alarcon August 18, 2020 04:29 PM UTC

Hi, basically I need to catch update event of the row with the uncommited data ( I'm using normal edit mode) , either pressing the update button or changing to the next row.
This row info will be sent to the API to be checked, API will send a true or false.

Or in other words.

How can I validate the entire row at once after pressing Update button or changing to a new row? In this moment I will validate all cells values and If all the values are OK, Ill commit the changes otherwise this will be cancelled (using args.cancel =true perhaps?)

Thanks!


VS Vignesh Sivagnanam Syncfusion Team August 19, 2020 03:03 PM UTC

Hi Carlos, 

Thanks for the update 

In previous update we have mentioned that we have support only for the client side validation and for server side validation we have logged the “Data Annotation” feature.    

 
To achieve your requirement as a workaround we suggest you to use actionBegin event of EJ2 Grid. The actionBegin event will be triggered for every grid action. In actionBegin event we can stop the save operation by defining e.cancel as true using the arguments. Once we stop the save operation we can send the edited data to the server-side using ajaxPost. 

After performing the validation in server-side in ajax success event we need to save the record using endEdit method of Grid. Please find the code example 


actionBegin(e) 
                if (!this.flag) { 
                    if (e.requestType == 'save') { 
                        var editedData = e.data; 
                        // The default edit operation is cancelled 
                        e.cancel = true; 
                        // Here you can send the updated data to your server using ajax call 
                        var ajax = new Ajax({ 
                            url: 'https://ej2services.syncfusion.com/production/web-services/', 
                            type: 'POST', 
                            contentType: 'application/json; charset=utf-8', 
                            data: JSON.stringify([editedData]) 
                        }); 
                        ajax.onSuccess = (args) => { 
                            // Flag is enabled to skip this execution when grid ends add/edit 
                            this.flag = true; 
                            // The added/edited data will be saved in the Grid 
                            this.grid.endEdit(); 
                        } 
                        ajax.onFailure = (args) => { 
                            // Save failed 
                           // The flag is disabled if operation is failed so that it can enter the condition on next execution 
                         this.grid.cancelEdit();  
                          this.flag = false; 
                        } 
                        ajax.send(); 
                    } 
              } 


Please get back to us if you need further assistance. 
 
Regards, 
Vignesh Sivagnanam 


Loader.
Up arrow icon