DataGrid Settings lifecycle related issues

I am facing an issue related to Settings. I am following the example of the Sale/Loading Settings IQueryable.

Looking at the source code I can see that when theData patameter is set, it calls the internal OnDataChanged() to execute which in turn calls the Reset() method which invokes the SaveSettings() method.

The issue that I am seeing is that somehow the Data parameter is set before the Settings parameter. This results the SaveSettings() method to invoke the SettingsChanged calleback before any settings have been applied on the grid which leads to my page persisting to storage the default settings and not my settings. Then when the page lifecycle comes to then OnAfterRenderAsync I load from the storage the default settings and not the ones the user sets up.

This highlights a race condition which I cannot pin point. Doing other examples with the same code (but different data source) seems to be working ok. Also, adding a 2 second delay in my data fetching seems to fix the issue in the problematic page which again highlights a race condition in the Settings life cycle management.

I am not sure why this happens (i will keep investigating) for my page however I dont understand why the Reset() method invokes the SaveSettings(). Is it possible to remove this call? I see no good reason for that to happen. Maybe make this call conditional to so SaveSettings takes a bool that controls if the SettingsChanged is invoked and when called from the Reset() it is called in way so the SettingsChanged is not invoked?

Thank you.

You can attach Radzen.Blazor.csproj to your application to debug what and when happens.

@echev that is exactly what I did and how I was able to describe what I put in my question.

The observations and the question I am asking I believe are reasonable. If the Data parameter is set before the Settings parameter then the settings persisted will be the default grid settings. Why is this happening in my case I am not sure but it happens 100% of the times whilst in other pages I have it does not. Hence it is possible that this happens and I am asking is you could consider to protect against it by following my suggestion or maybe in a different way.

If you believe you know a way to improve this functionality without breaking anything feel free to submit pull request.

Thank you @enchev, and happy to do so. I was hopping for some insight though from you given you are far more familiar with the code.

First, what purpose does it serve to call the SaveSettings() from the OnDataChanged()? I see this is avoided for when the LoadData is set. Why allow it when the LoadData is not set?

Second, am I right to assume that there is no guarantee on the order parameters are processed? If that is correct then the OnDataChanged() should be guarding against calling the SaveSettings(), something similar to what is done when LoadData is set. Would you agree?

Thank you.

When using LoadData event there is a difference lifecycle and different way to load settings. You can check our demo for reference.

Thank you @enchev

For the non LoadData lifecycle, is there a reason why the SaveSettings is called when the OnDataChanged() is executed?

Hey @amavroudakis,

No, there is no such call:

It’s called only Reset() where there is explicit check if there is no LoadData.

UPDATE: Looks like I misunderstood your note. We will review the logic of this call and might remove it for the next update Monday.