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

Javascript ejGrid undo row delete if server returns error

I'm using ejGrid with the toolbarSettings that include the "delete" option. When a row is deleted, it calls a Web Api delete action in my controller. Sometimes, an error can occur and the server cannot delete the record for some reason. My jQuery function executed the error code and I display the error message on the page. However, the ejGrid still removes the record on the client side. The row disappears in the ejGrid.
How do I undo this row removal in the ejGrid when an error comes back from the server?

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team September 6, 2016 07:15 AM UTC

Hi Ray, 

Thanks for contacting Syncfusion support. 

We created a sample in web API adapter with a delete action in the controller. In the controller we throw an exception in delete action before the server delete the record. When we delete the record in the sample it throws an exception and grid does not remove the record from the client side. 

In our sample we display the error message using actionFailure event of ejGrid. We can handle any exceptions(server-side) in the actionFailure event. In this event we can get error messages in arguments and display the error messages in the alert window. 


Find the code example and sample: 


<script type="text/javascript"> 
    $(function () { 
        $("#Grid").ejGrid({ 
                        dataSource: ej.DataManager({ url: "/api/Orders", adaptor: "WebApiAdaptor" }), 
            allowPaging: true, 
           editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
            pageSettings: { pageSize: 4 }, 
            actionFailure : "Failure", 
            toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Delete] }, 
            columns: [ 
                        --------------------- 
            ] 
        }); 
    }); 
 
function Failure(args) { 
        alert(args.error.error.statusText); 
    } 
</script> 
 
----------------------------------------------------- 
   public void Delete(int id) 
        { 
            throw new Exception(); 
            var order = db.EmployeePhotoes.Find(id); 
            db.EmployeePhotoes.Remove(order); 
            db.SaveChanges(); 
        } 


Refer to the Help document for the actionFailure event. 


For your convenience we attached a video demonstration. 


To reproduce the issue we need the following details, 

1. Code example of a Grid and controller. 

2. Essential Studio Version details. 

3. If possible, replicate the issue in the attached sample. 

Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Up arrow icon