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

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

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

thanks

5 Replies

PS Pavithra Subramaniyam Syncfusion Team 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. 



SA Samuel 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


PS Pavithra Subramaniyam Syncfusion Team 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. 



SA Samuel February 11, 2019 09:12 AM UTC

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


PS Pavithra Subramaniyam Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon