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
close icon

Changed value is not reflecting on grid

I used dynamic data binding example from this url https://ej2.syncfusion.com/blazor/documentation/grid/how-to/change-datasource-dynamically/.
This code is working fine, but when I change only one value it is not reflecting changes on grid. My question is how to perferm refresh grid after sinal record change. Secondly If there are more than 8 records then after page change it reflect changes.

@page "/refreshgrid"
@using Syncfusion.EJ2.Blazor.Grids
@using Syncfusion.EJ2.Blazor.Buttons

<EjsButton OnClick="Change">Change data source dynamically</EjsButton>

<EjsGrid DataSource="@Orders" AllowPaging="true">
    <GridPageSettings PageSize="8"></GridPageSettings>
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type=ColumnType.Date TextAlign="TextAlign.Right" Width="130"></GridColumn>
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>

   public List<Order> Orders { get; set; }
   protected override void OnInitialized()
      Orders = Enumerable.Range(1, 12).Select(x => new Order()
         OrderID = 1000 + x,
         CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
         Freight = 2.1 * x,
         OrderDate = DateTime.Now.AddDays(-x),
   public void Change()
      //// Data source is modified dynamically
      //this.Orders = Enumerable.Range(1, 45).Select(x => new Order()
      //   OrderID = 100 + x,
      //   CustomerID = (new string[] { "CHOPS", "HANAR", "SUPRD", "TOMSP", "VINET" })[new Random().Next(5)],
      //   Freight = 1.1 * x,
      //   OrderDate = DateTime.Now.AddDays(-x),

      Orders[0] = new Order { CustomerID = "CHOPS", Freight = 123, OrderDate = new DateTime(2020, 2, 2), OrderID = 112233 };
   public class Order
      public int? OrderID { get; set; }
      public string CustomerID { get; set; }
      public DateTime? OrderDate { get; set; }
      public double? Freight { get; set; }

3 Replies

VN Vignesh Natarajan Syncfusion Team January 14, 2020 04:49 AM UTC

Hi Jawaid,  
Greetings from Syncfusion support.  
Query1: “My question is how to perferm refresh grid after sinal record change  
We suggest you to achieve your requirement by binding your data in form of Observable collection. So that changes done externally will be automatically reflected inside the grid without calling any refresh method of grid. We have handled the observable collection inside our source. Refer the below our UG document and online demo for your reference. 
If you still wish to use IENumerable data and to refresh the Grid instead of Observable collection, kindly use Refresh() method of Grid to achieve your requirement. Refer the below code example.  
<EjsGrid @ref="Grid"> 
. . . . . . . .  
EjsGrid<OrdersGrid> Grid { get; set; }  
Query2: “Secondly If there are more than 8 records then after page change it reflect changes. 
Yes. While binding the Grid DataSource in form of list of IENumerable collection, we will fetch entire data and bind the current page records to Grid. So while paging we will bind the current page records from the data newly and grid gets refreshed. So if you have changed the Grid data (IEnumerable collection) externally it will reflected in grid while paging since Grid will be refreshed on certain actions.    
Please get back to us if you have further queries.    
Vignesh Natarajan.  

JA Jawaid Akhter January 14, 2020 07:54 AM UTC

Now It is working..

Thank You

VN Vignesh Natarajan Syncfusion Team January 15, 2020 01:17 AM UTC

Hi Jawaid,  
Thanks for the update. 
We are glad to hear that you query has been resolved by our solution.  
Kindly get back to us if you have further queries. 
Vignesh Natarajan.  

Live Chat Icon For mobile
Up arrow icon