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.
Unfortunately, activation email could not send to your email. Please try again.

OData V4 Validation rules

Thread ID:

Created:

Updated:

Platform:

Replies:

125590 Aug 26,2016 05:30 AM Mar 29,2018 08:28 AM JavaScript 5
loading
Tags: ejGrid
Andrea Perazzolo
Asked On August 26, 2016 05:30 AM

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

Jayaprakash Kamaraj [Syncfusion]
Replied On August 29, 2016 08:39 AM

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. 


Andrea Perazzolo
Replied On September 16, 2016 09:37 AM

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.

Jayaprakash Kamaraj [Syncfusion]
Replied On September 19, 2016 09:32 AM

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. 


mohit
Replied On March 28, 2018 01:20 PM

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.

Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On March 29, 2018 08:28 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;