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

Grid not refreshing when new data is added

Hello,

I am binding data to a grid component via the DataSource property. I do it like this <Grid DataSource=MyList ... >. However when I make a call to my service and change MyList to a new list the data in the grid is not refreshed. This used to work for me in the prior versions.


7 Replies

RS Renjith Singh Rajendran Syncfusion Team February 3, 2020 08:48 AM UTC

Hi Krasimir, 

Thanks for contacting Syncfusion support. 

We suggest you to call the “StateHasChanged” method to reflect the modified changes in Grid. We have prepared a sample based on this requirement, please download the sample form the link below, 

Please refer the code below, 

<EjsButton @onclick="ChangeData">Change Grid Data</EjsButton> 
 
<EjsGrid ID="Grid" TValue="Orders" DataSource="@OrderData" AllowPaging="true"> 
    ... 
</EjsGrid> 
 
 
@code { 
    public List<Orders> OrderData { get; set; } 
    protected override void OnInitialized() 
    { 
        OrderData = Enumerable.Range(1, 75).Select(x => new Orders() 
        { 
            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 async void ChangeData() 
    { 
        OrderService _craftService = new OrderService(); 
        OrderData = await _craftService.GetOrdersAsync(); 
        StateHasChanged(); 
    } 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



KI Krasimir Ivanov February 7, 2020 12:48 AM UTC

Yes, I know I have to invoke StateHasChanged. The grid is working in most of the places however in some of the more specific cases it is not being refreshed. This worked perfectly before but after a couple of updates to the syncfusion versions it stopped working.


RS Renjith Singh Rajendran Syncfusion Team February 7, 2020 10:26 AM UTC

Hi Krasimir, 

Thanks for contacting Syncfusion support. 

Query 1 : however in some of the more specific cases it is not being refreshed 
Could you please share the complete details regarding the specific cases. Is this specific cases involve updating a single row data in Grid? If you are updating the value for a single row data(IEnumerable data in Grid) then it is a must to call the Grid’s Refresh() method to reflect the changes to Grid. Or else you can bind data to Grid as ObservableCollection.  

Please refer the documentation and online sample demos showing the CRUD with ObservableCollection as data in Grid. 
 
Query 2 : This worked perfectly before but after a couple of updates to the syncfusion versions it stopped working. 
In our older versions, we have deep watched IEnumerable changes. This had performance impacts. So to avoid this we have withdrawn IEnumerable deep watching with our latest versions. So please use the StateHasChanged method as suggested in our previous update to achieve this requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



KI Krasimir Ivanov February 7, 2020 04:36 PM UTC

Yes, Refresh() fixed it for me. Didn't know about the internal state changes. Thank you for the help! :)


RS Renjith Singh Rajendran Syncfusion Team February 10, 2020 09:11 AM UTC

Hi Krasimir, 

Thanks for your update. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



JM Jelard Macalino February 21, 2020 03:50 AM UTC

Hi I am having the same problem.  I am using an IEnumerable in the DataSource and whenever I refreshed it with a new list from my service the grid does not refresh.  I tried StateHasChanged() as recommended but it doesn't work.  I also tried refreshing the grid. It works but only on Debug but not on Release and start without debugging. Below is the error

Error: System.NullReferenceException: Object reference not set to an instance of an object.

I am using v17.4.0.49


RS Renjith Singh Rajendran Syncfusion Team February 21, 2020 07:08 AM UTC

Hi Jelard, 

Thanks for contacting Syncfusion support. 

We have prepared a sample based on this reported scenario. But dynamic update of data works fine from our side. Please download the sample from the link below, 

Please refer the above sample and the suggestions which we have provided in our previous update dated 2/7/2020. And if you are still facing difficulties then we need more details to further proceed on this and provide you a solution. Kindly get back to us with the following details for better assistance. 

  1. Share the sample which you have tried from your side. Or if possible reproduce the problem with the attached sample and share with us for further validation.
  2. Share the video demo showing the problem you are facing.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Live Chat Icon For mobile
Up arrow icon