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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changed value is not reflecting on grid

Thread ID:

Created:

Updated:

Platform:

Replies:

150619 Jan 13,2020 03:47 PM UTC Jan 15,2020 01:17 AM UTC Blazor 3
loading
Tags: Grid
Jawaid Akhter
Asked On January 13, 2020 03:47 PM UTC

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>
    <GridColumns>
        <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>
    </GridColumns>
</EjsGrid>

@code{
   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),
      }).ToList();
   }
   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),
      //}).ToList();

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




Vignesh Natarajan [Syncfusion]
Replied On 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>  
. . . . . . . .  
EjsGrid<OrdersGrid> Grid { get; set; }  
Grid.Refresh(); 
 
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.    
 
Regards, 
Vignesh Natarajan.  


Jawaid Akhter
Replied On January 14, 2020 07:54 AM UTC

Great..
Now It is working..

Thank You

Vignesh Natarajan [Syncfusion]
Replied On 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. 
 
Regards, 
Vignesh Natarajan.  


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

Live Chat Icon For mobile
Live Chat Icon