DataGrid refresh on Reload/LoadData

Hi,

I am currently faced with something I would consider to be a bug:
I have a DataGrid which get's its data assigned in the LoadData event. Everything starts to work out, if I additionally set the data count attribute in the event.
However, I am unable to reload the data through e.g. a button click. I have changed the data on the backend database, but this is not reflected in the data grid. Additionally, when I enter a new record and click my button, I get the newly created record from the backend, but the changes of previous ones are not considered. For me, this means there is too much data cached and not renewed.

Do you agree?

If you need to reload the DataGrid component you can execute Reload() method.

That's what I am doing, but the grid is not reflecting changes from the backend when I click my button:
image002
image001

I did some additional analysis.
Apparently, new records are added to the datagrid if I create them on the backend and press the refresh button. Still, changes to already cached records are not updated.

I even implemented some sort of redirects which are not resulting in a refreshed cache. Any suggestions?

Are you sure the data is updated? You can use the Visual Studio debugger to verify what data is being set to the Data property of the Radzen DataGrid.

Can you tell me how this is done? I can tell you that requests are sent to the database. I can see the statements being print.

Btw: I created a new application and the exact same code works in there. Question is how I can fix my already existing one?

I have the same issue as well. I have a grid that I refresh on a timer that updates the grid data data source. Only add and deleted records refresh. Eventually after enough time goes by the records will get updated. If I edit a row through an edit dialog the row is updated correctly but not if it’s changed outside of the application. I have confirmed the data is showing the change when debugging but it’s as if the grid doesn’t know that a value has changed.

Try to execute Reload() method of the DataGrid.

So I did some more testing and looked at the data. The grid data is not showing the correct data unless there is a new record added or a recorded removed. I have debugged the grid load event and it is not getting the current data for records already bound to the grid. I am getting the data in the gridload event and have a timer that calls the grid0.reload() method every 10 seconds.

Here is the grid loaddata event:
protected async System.Threading.Tasks.Task Grid0LoadData(LoadDataArgs args)
{
myTicketsGridEvent = args;

        myTicketsGridBaseFilter = "";

        myTicketsGridBaseFilter = "StatusTypeId != 5 && (AssignedToName == \"" + Security.User.Name + "\" || SecondaryAssignedToName.Contains(\"" + Security.User.Name + "\"))";

        if (string.IsNullOrEmpty(myTicketsGridEvent.Filter)) {
            myTicketsGridFilter = myTicketsGridBaseFilter;
        }

        if (!string.IsNullOrEmpty(myTicketsGridEvent.Filter)) {
            myTicketsGridFilter = myTicketsGridEvent.Filter + " && " + myTicketsGridBaseFilter;
        }

        myTicketsSortDefault = "LastActivityDateTime asc";

        myTicketsSort = myTicketsSortDefault;

        if (!string.IsNullOrEmpty(myTicketsGridEvent.OrderBy)) {
            myTicketsSort = myTicketsGridEvent.OrderBy;
        }

        try
        {
            var crownCrmDbGetTicketsResult = await CrownCrmDb.GetTickets(new Query() { Filter = $@"{myTicketsGridFilter}", OrderBy = $"{myTicketsSort}", Expand = "Tasks,Projects" });
            getMyTicketsResult = crownCrmDbGetTicketsResult;

            getMyTicketsResultCount = crownCrmDbGetTicketsResult.Count();
        }
        catch (Exception crownCrmDbGetTicketsException)
        {
                NotificationService.Notify(NotificationSeverity.Error, $"Error", $"{crownCrmDbGetTicketsException}", 5000);
        }
    }

And here is the timer elapsed event:
private async void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
await InvokeAsync(() =>
{
try
{
Console.WriteLine("grid0.Reload() and grid1.Reload() starting");
try
{
grid0.Reload();

                }
                catch (Exception crownCrmDbGetTicketsException012)
                {
                    NotificationService.Notify(NotificationSeverity.Error, $"Error", $"{crownCrmDbGetTicketsException012}", 5000);
                }

                timerRefreshResult = DateTime.Now.ToString();

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:  " + ex.Message);
            }

            this.StateHasChanged();
            
        });
        
    }

Can you post the DataGrid razor declaration also?

Sure. I had issues posting the razor so I attached it as a zip.
MyDashboard.zip (3.3 KB)

Not sure why is not working for you. I've modified this demo with the following code and the LoadData method is called every 5 sec:

@code {
    int count;
    IEnumerable<Employee> employees;

    RadzenGrid<Employee> grid;

    protected override void OnInitialized()
    {
        base.OnInitialized();

        Timer timer = new Timer(5000);
        timer.Elapsed += (s,e)=> { InvokeAsync(grid.Reload); };
        timer.Start();
    }

    async Task LoadData(LoadDataArgs args)
    {
        var result = await service.GetEmployees(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);
        employees = result.Value.AsODataEnumerable();
        count = result.Count;

        StateHasChanged();
    }
}

Have you checked data changes that you did to the backend meanwhile your page refreshing?

To me, it looks like the whole loaddata event has caching which prevents some functionalities.
For example the pagination does not work for me too when using the load data event.
Grid is showing the pages, but the pagesize is not considered and all records are presented.

1 Like

This issue does not appear to be resolved and I'm dealing with the exact same problem. Edits do not appear in the grid unless I refresh the page (F5 or programmatically refresh). Adds and Deletes will appear, I can even insert a new record via SQL insert before clicking Save on an Edit operation - the new record will appear, but the changes do not. Clicking "Edit" on the same record will show the recent edits in edit window, but clicking "Save" will not show the edits on the grid.
I'm subscribing to the Dialog.Close() event, and calling Grid.Reload() in there.
The most ridiculous thing is that this same code works on another project without issue. Why will it not work here?

Hi all,
I have very similar issue. All CRUD operations work just fine (the changes appear in my database) but the datagrid only shows the CRUD changes after manually refreshing the page. I invoke a simple "await grid.Reload()" after any CRUD method, but it seems as if the reload() method does not do anything. I already tried a few things to try to get it to work, but without success.
Do I need something else besides the "await grid.Reload()" to get it to work?

Reload() method of the DataGrid will just rebuild the component UI using the value provided in Data property. If you use a service to retrieve your data you might need to to request it.

Okay, that makes sense. Thanks for the fast reply!