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.
Syncfusion Feedback

How to perform server validation on Grid Excel Like Edit

Thread ID:

Created:

Updated:

Platform:

Replies:

109006 May 25,2013 05:05 PM UTC Oct 7,2013 07:20 AM UTC ASP.NET MVC (Classic) 6
loading
Tags: Grid
Arief Darmawan
Asked On May 25, 2013 05:05 PM UTC

Dear Syncfusion,

I have been a week using Syncfusion and would like your advice per subject, how to perform server validation on Grid Excel Like edit.

For instance I add 5 lines of sales order items (Item, Qty, Price and Discount). I need to validate if :

- Discount of each item is should be less than specific value (need to read discount master table)

- Sum of all price * qty should be higher than specific value (need to read salesperson table)

Thanks in advance.


Hariharan J V [Syncfusion]
Replied On June 4, 2013 01:10 PM UTC

Hi Arief Darmawan,

Thanks for using Syncfusion products.

Currently we are working on this with high priority and we are facing some difficulty in cancelling values on OnSave clientside Event, so we will update you in two business days(June 6,2013).

Please let us know if you have any other concerns,

Regards,
Hariharan J.V.

Arief Darmawan
Replied On June 21, 2013 04:36 PM UTC

Hi Hariharan,

Thanks for the response.

Is any progress on the solution ?

I manage to solve the issue, but I need to re-code all, including build my own jquery grid :(


Satheeskumar S [Syncfusion]
Replied On June 26, 2013 10:27 AM UTC

Hi Arief Darmawan,

 

 

Thanks for your interest in Syncfusion products.

 

We are Sorry for the inconvenience caused. We have prepared a sample to demonstrate the Server Side Validation in Excel like Edit.

In that sample we have done the validation based on the Quantity and Unit Price Value. The product of Quantity and Unit Price of an each item is greater than 500. If the validation is success then update the record to the database, otherwise it is simply display the error message using Response.AddHeader method.

 

Please refer the below code snippet for Server side Validation.

 

[Controller]

 

[AcceptVerbs(HttpVerbs.Post)]

public ActionResult BulkSave([Bind(Prefix = "updatedRecords")]IEnumerable<EditableOrder> orders, [Bind(Prefix = "addedRecords")]IEnumerable<EditableOrder> addRcrds, [Bind(Prefix = "deletedRecords")]IEnumerable<EditableOrder> delRcrds)

 {

            string msg=string.Empty;

            if (orders != null)

            {

                      foreach (var ord in orders)

                     {

                              if ((ord.Quantity * ord.UnitPrice) > 500)

                             {

                                      OrderRepository.Update(orders);                       

                             }

                             else

                             {

                                      msg = "Total Amount is less than 500 for the OrderID-"

                                                                                                         +ord.OrderID;

                                      Response.AddHeader("Error", msg);

                              }

                     }             

 }         

if (addRcrds != null)

                        OrderRepository.Add(addRcrds);

            if (delRcrds != null)

                        OrderRepository.Delete(delRcrds);

            var data = OrderRepository.GetAllRecords();

            return data.GridJSONActions<EditableOrder>();

}

 

[Cshtml]

                       

<div class="Status" style="color: red; font-family: ‘Times New Roman';">

 

</div>

 

 

[Script]

 

 

<script type="text/javascript">

 

    $("#Json").ajaxSuccess(function (evt, request, settings)

   {

              $('.Status').html(request.getResponseHeader("Error"));

    });

 

</script>

 

For your convenience we have attached a sample. Could you please refer that sample and get back to us if you have any queries.

 

 

Let us know if you have any other concerns.

 

 

Thanks & Regards,

 

Satheeskumar S



ExcelEdit_579b82ad.zip

Dan Guisinger
Replied On October 2, 2013 06:01 PM UTC

Has this not been fixed yet?  I tried manually doing a Regular Expression in OnCellSave and then performed a cancel event, and the control blows up.

If I switch to Inline editing, each field validates based on the data model validation attributes.
Excel mode is terribly crippled if you can't properly validate data.

I don't feel like I should need to manually handle validation  if other modes pick up validation rules automatically.

Dan Guisinger
Replied On October 2, 2013 08:58 PM UTC

Never mind, apparently its disabled on whatever field you identify as the unique key.  When you initially enter a value, it won't validate under that circumstance.  I would still consider that a flaw, but it was something I could work around.  (In our case, entering vehicle information, the VIN number is unique, so I used it as a key, but I also want it to match a Regular Expression to make sure its valid)

Hariharan J V [Syncfusion]
Replied On October 7, 2013 07:20 AM UTC

Hi Dan,

Thanks for your update.

We have modified the above given sample to achieve your requirement("validation on product id is valid while adding records"). We are used Order_Detail table in the above given sample, it may contains duplicate(OrderID) values, so we suggest you to use ProductID as primary key for unique value. Please refer the below code snippets.

[HomeController.cs]
 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult BulkSave([Bind(Prefix = "updatedRecords")]IEnumerable<EditableOrder> orders, [Bind(Prefix = "addedRecords")]IEnumerable<EditableOrder> addRcrds, [Bind(Prefix = "deletedRecords")]IEnumerable<EditableOrder> delRcrds)
        {
            string msg=string.Empty;
            if (orders != null)
            {
                foreach (var ord in orders)
                {
                    if ((ord.Quantity * ord.UnitPrice) > 500)
                    {
                        OrderRepository.Update(orders);                        
                    }
                    else
                    {
                        msg = "Total Amount is less than 500 for the ProductID-" + ord.ProductID;
                        Response.AddHeader("Error", msg);
                    }
                }
            }

            if (addRcrds != null)
            {
                foreach (var ord in addRcrds)
                {
                    EditableOrder flag = OrderRepository.GetAllRecords().Where(o => o.ProductID == ord.ProductID).FirstOrDefault();
                    if (flag == null)
                    {
                        OrderRepository.Add(addRcrds);
                    }
                    else
                    {
                        msg = "This ProductID already exists-" + ord.ProductID;
                        Response.AddHeader("Error", msg);
                    }
                }
            }
            if (delRcrds != null)
                OrderRepository.Delete(delRcrds);
            var data = OrderRepository.GetAllRecords();
            return data.GridJSONActions<EditableOrder>();
        }

And the same sample can be downloaded from the below link.

Sample: www.syncfusion.com/downloads/support/directtrac/general/ExcelEdit1833092173.zip

Please let us know if you need any further assistance.

Regards,
Hariharan J.V.

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.

Warning Icon 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.Close Icon

;