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

OData V4 Validation rules

Hi,
I have a problem regarding Data Validation using the OData Datamanager on the grids
I have specifically a column datetime  that has a non nullable value. If I try to use the required client validation, it does not fire.
I have included the jquery validation scripts.
I have even tried the remote validation, but when the ModelState is not valid on the server, I haven't any result on the client side.
Maybe I am doing anything qrong.
Could you please send me a working example of remote validation using OData

     Thanks in advance

   Andrea Perazzolo

5 Replies

JK Jayaprakash Kamaraj Syncfusion Team August 29, 2016 12:39 PM UTC

Hi Andrea, 

Thank you for contacting Syncfusion support.   
  
We have created a sample with remote validation using OData. In that sample, we have handled validations in server side grid operations(insert/update/delete). Please refer to the below code example and sample.   

// PUT odata/Suppliers(5) 
        public IHttpActionResult Put([FromODataUri] int key, Order supplier) 
        { 
            if (!ModelState.IsValid) 
            { 
                return BadRequest(ModelState); 
            } 
 
 
 
            return Updated(supplier); 
        } 



Please try the sample and let me know if any concern.     

Regards, 

Jayaprakash K. 



AP Andrea Perazzolo September 16, 2016 01:37 PM UTC

Thank you for the reply.
Sorry, I was on vacation and I haven't checked the sample till today.
I have tried your sample, and sent en edit for the record with null date, that gives me a ModelState invalid for the Order record, but in the grid I don't see anything that shows me errors only the fact that the record remains in edit state, but no Validation messages are shown.
I remembered from an old version of controls, that I had some tooltips with the validation errors  in the grid, but that time I was using validation of local data.   

    Thanks in advance

P.S. I have changed only the version of the Syncfusion.EJ in the Web Coonfig to .26 because I have not yet installed the SP assemblies, I am using only the CDN javascript files.


JK Jayaprakash Kamaraj Syncfusion Team September 19, 2016 01:32 PM UTC

Hi Andrea, 

If you want to show the validation message in client side, then you need to set the validationRules property for the grid columns. Please refer to the below code example. 

columns: [ 
                    { field: "OrderID",isPrimaryKey:true, headerText: 'Order ID', width: 90 }, 
                    { field: "ShipCity",headerText: 'ShipCity', width: 90 }, 
                    { field: "EmployeeID", headerText: 'EmployeeID', textAlign: ej.TextAlign.Right, width: 80 }, 
                    { field: "OrderDate", headerText: "OrderDate", format: "{0:MM/dd/yyyy}", validationRules: { date: true }} 
            ] 
 
If client side validation is enabled, first the data is validated at client side and only if it satisfies the criteria, the controller action is triggered.  
We can perform the server side validation and throw exception at controller when the validation fails which can be handled using ActionFailure event of the grid. Please refer to the below help document, code example and sample. 


            actionFailure: function(args){ 
                alert(args.error.statusText);//here we will get error message 
            }, 
…………………. 
 
public IHttpActionResult Post(Order supplier) 
        { 
            if (!ModelState.IsValid) 
            { 
                return BadRequest(ModelState); 
            } 
 
            db.Orders.Add(supplier); 
            db.SaveChanges(); 
 
            return Created(supplier); 
        } 


Regards, 

Jayaprakash K. 



MO mohit replied to Jayaprakash Kamaraj March 28, 2018 05:20 PM UTC

Hi Andrea, 

If you want to show the validation message in client side, then you need to set the validationRules property for the grid columns. Please refer to the below code example. 

columns: [ 
                    { field: "OrderID",isPrimaryKey:true, headerText: 'Order ID', width: 90 }, 
                    { field: "ShipCity",headerText: 'ShipCity', width: 90 }, 
                    { field: "EmployeeID", headerText: 'EmployeeID', textAlign: ej.TextAlign.Right, width: 80 }, 
                    { field: "OrderDate", headerText: "OrderDate", format: "{0:MM/dd/yyyy}", validationRules: { date: true }} 
            ] 
 
If client side validation is enabled, first the data is validated at client side and only if it satisfies the criteria, the controller action is triggered.  
We can perform the server side validation and throw exception at controller when the validation fails which can be handled using ActionFailure event of the grid. Please refer to the below help document, code example and sample. 


            actionFailure: function(args){ 
                alert(args.error.statusText);//here we will get error message 
            }, 
…………………. 
 
public IHttpActionResult Post(Order supplier) 
        { 
            if (!ModelState.IsValid) 
            { 
                return BadRequest(ModelState); 
            } 
 
            db.Orders.Add(supplier); 
            db.SaveChanges(); 
 
            return Created(supplier); 
        } 


Regards, 

Jayaprakash K. 


I am using xsio library to export datatable to worksheet in. Wpf application.


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team March 29, 2018 12:28 PM UTC

Hi Mohit,  
 
Please refer to below documentation to know more on Importing Data from Datatable to worksheet  
 
 
Please refer to below documentation to know more on working with Data validation.  
 
 
If you have an specific requirement, we request you to share the same in detail to provide you proper solution from our side.  
 
Regards,  
Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon