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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

using WebApiAdaptor grid does not refresh/reload after save/update

Thread ID:

Created:

Updated:

Platform:

Replies:

142557 Feb 10,2019 07:49 AM UTC Feb 11,2019 09:18 AM UTC ASP.NET MVC - EJ 2 5
loading
Tags: Grid
Samuel
Asked On February 10, 2019 07:49 AM UTC

I am using WebApiAdaptor javascripthow do i make grid  refresh/reload after save/update?

thanks

Pavithra Subramaniyam [Syncfusion]
Replied On February 11, 2019 07:23 AM UTC

Hi Samuel, 
 
Thanks for contacting Syncfusion support.  
 
Query: I am using WebApiAdaptor javascripthow do i make grid  refresh/reload after save/update? 
 
By default Grid will be refreshed with new data automatically after save action. You need not refresh the Grid manually. We have prepared a simple sample based on your requirement. Please refer to the below code example and sample link. 
 
[index.cshtml]  
  var data = new ej.data.DataManager({ 
        url: '/api/order', 
        adaptor: new ej.data.WebApiAdaptor 
    }); 
 
    var grid = new ej.grids.Grid({ 
        dataSource: data, 
        allowPaging: true, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, 
        columns: [ 
            { field: 'OrderID', headerText: 'ID', textAlign: 'Right', width: 120, isPrimaryKey: true }, 
            { field: 'CustomerID', headerText: 'Custome ID', textAlign: 'Right', width: 120 }, 
            { field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right' } 
        ] 
    }); 
 
    grid.appendTo('#Grid'); 
 
[Controller.cs] 
public class OrderController : ApiController 
    { 
        // GET: api/Order 
        public object Get() 
        { 
             
            var queryString = System.Web.HttpContext.Current.Request.QueryString; 
            int skip = Convert.ToInt32(queryString["$skip"]); //paging 
            int take = Convert.ToInt32(queryString["$top"]); 
            var data = OrdersDetails.GetAllRecords(); 
            
            return new 
            { 
                Items = data.Skip(skip).Take(take), 
                Count = data.Count() 
                //  return order; 
            }; 
        } 
 
        // POST: api/Order 
       [HttpPost] 
        public object Post([FromBody]OrdersDetails value) 
        { 
            OrdersDetails.GetAllRecords().Add(value); 
            var Data = OrdersDetails.GetAllRecords().ToList(); 
            int count = Data.Count(); 
            return Json(new { result = Data, count = count }); 
        } 
 
        // PUT: api/Order/5 
        [HttpPut] 
        public object Put([FromBody]OrdersDetails value) 
        { 
            var ord = value; 
            OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
             .  .  . 
            return value; 
        } 
 
        // DELETE: api/Order/5 
        public object Delete(int id) 
        { 
            OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault()); 
            return Json(id); 
        } 
    } 
 
 
Could you please provide the below details that will be helpful for us to provide a better solution as early as possible. 
 
  1. Share the stack trace if you are facing any script error while updating.
  2. Share the grid and controller code.
  3. Please reproduce the issue in the above sample if possible.
 
Regards, 
Pavithra S. 


Samuel
Replied On February 11, 2019 07:27 AM UTC

Thank you for yuor reply.


I think something may be off with my setup. your example works.
Is there any way I can hook into the after update event and also how to manually refresh there?

Thanks

Pavithra Subramaniyam [Syncfusion]
Replied On February 11, 2019 08:35 AM UTC

Hi Samuel, 
 
Thanks for your update.  
 
You can achieve your requirement by using the “actionComplete” with requestType “save”. In this event your can refresh the Grid by using the “refresh()” method. Please refer to the below code example and Documentation link. 
 
[index.cshtml]  
  var data = new ej.data.DataManager({ 
        url: '/api/order', 
        adaptor: new ej.data.WebApiAdaptor 
    }); 
 
    var grid = new ej.grids.Grid({ 
        dataSource: data, 
        allowPaging: true, 
       actionComplete: (e) => { 
            if (e.requestType == 'save') { 
                grid.refresh(); 
            } 
        }, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, 
        columns: [ 
            { field: 'OrderID', headerText: 'ID', textAlign: 'Right', width: 120, isPrimaryKey: true }, 
            { field: 'CustomerID', headerText: 'Custome ID', textAlign: 'Right', width: 120 }, 
            { field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right' } 
        ] 
    }); 
 
    grid.appendTo('#Grid'); 
 
                              https://ej2.syncfusion.com/documentation/api/grid/saveEventArgs/  
                              https://ej2.syncfusion.com/documentation/api/grid/#refresh  
 
Regards, 
Pavithra S. 


Samuel
Replied On February 11, 2019 09:12 AM UTC

Thank you so much, it worked perfectly!
You guys rock!

Pavithra Subramaniyam [Syncfusion]
Replied On February 11, 2019 09:18 AM UTC

Hi Samuel,  

Thanks for your update.  

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

;