Reloading Content In Grid

Hi,

I have a case where external changes will be made to the data in the grid I want to be able to refresh the content in the grid to get the updated data from the database from within the page.

Many thanks,

Avi

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team February 16, 2018 11:34 AM UTC

Hi Avi, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we suspect that you want to update the Grid with the modified data. So, we suggest you to use updateRecord() method of ejGrid control. 

Also if you want to made the changed in database then we suggest you to enable adaptors for persisting the data in server. So, we suggest you to use the RemoteSave adaptor in your sample and make the CRUD operations in the server side. 
 
Refer the below code example. 
 
[Index.cshtml] 
 
@(Html.EJ().Grid<object>("FlatGrid") 
         .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).UpdateURL("/Grid/Update"). 
         InsertURL("/Grid/Insert").RemoveURL("/Grid/Remove").Adaptor(AdaptorType. RemoteSaveAdaptor)) /* enabling the remote save adaptor */ 
 
        .AllowPaging()    /*Paging Enabled*/ 
        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
        .ToolbarSettings(tool => { 
            tool.ShowToolbar().ToolbarItems(toolitem => 
            { 
                toolitem.AddTool(ToolBarItems.Add); 
                toolitem.AddTool(ToolBarItems.Delete); 
                toolitem.AddTool(ToolBarItems.Edit); 
                toolitem.AddTool(ToolBarItems.Update); 
                toolitem.AddTool(ToolBarItems.Cancel); 
            }); 
         
        }) 
        .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
             
            ------------- 
 
        })) 
 
 
 
[HomeCOntroller.cs] 

        public ActionResult Update(Orders value)  
        { 
            var ds = order.ToList();   //Update the modified record in datasource 
            Orders result = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault(); 
            if (result != null) 
            { 
                result.OrderID = value.OrderID; 
                result.CustomerID = value.CustomerID; 
                result.ShipCountry = value.ShipCountry; 
                result.ShipCity = value.ShipCity; 
                result.ShipAddress = value.ShipAddress; 
            } 
            return Json(value, JsonRequestBehavior.AllowGet); 
        } 
 
       public ActionResult Insert(Orders value) 
       { 
           Random ran = new Random();  
           value.OrderID = ran.Next();// For isIdentity column, need to generate a new value while inserting new record. 
           order.Insert(0, value); //Add a new record in datasource 
           return Json(value, JsonRequestBehavior.AllowGet); 
            
       }     
                         
        public ActionResult Delete(int key) 
        {   
            Orders result = order.Where(o => o.OrderID == key).FirstOrDefault(); 
            order.Remove(result); //Delete a record in datasource       
            return Json(key, JsonRequestBehavior.AllowGet); 
        } 


Refer the help documentation. 



Regards, 
Thavasianand S.  


Loader.
Up arrow icon