Restored GridState from Previous Saved GridState, Crashes Blazor Circuit Handler or doesn't display grid correctly

2 Answers 31 Views
Grid
Jerdobi
Top achievements
Rank 1
Iron
Iron
Jerdobi asked on 21 Jul 2022, 08:42 PM

Scenario:

Want to save and restore the GridState between sessions to save the users columns being displayed, sort order and filter status.

Problem:

If the code to the TelerikGrid is changed between saving and restoring the GridState, the TelerikGrid will not display the data correctly at a minimum and at worst can crash Blazor circuit completely.

Solution:

Restoring a GridState from a previous version of the GridState should not crash the site on the restore.  It should realize the state isn't valid for this TelerikGrid and should do no harm.

Workaround:

Is there a coding pattern for saving and restoring GridState to local storage that would work around column changes between saving and restoring the GridState?

Repro:

  1. Save the GridState to local storage, so that user can come back later and the state is restored to provide the same view to the user.


  2. Change the code for the Telerik Grid Control to show completely different columns. 
  3. The user comes back to the UI and the code restored the GridState from the previous save before TelerikGrid was changed.



  4. Best case, the TelerikGrid format restored doesn't match what was saved previously and columns displayed are inconsistent to what was saved previously is the best case and need to reset the GridState.

    GridState<PackageRequest> desiredState = new GridState<PackageRequest>();

  5. Worst case, the TelerikGrid throws a unhandled System.ArgumentException exception and crashes the entire page.
    (see attached screen shot and the exception from Azure App Insights).

 

 

 

2 Answers, 1 is accepted

Sort by
0
Timothy J
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 21 Jul 2022, 08:54 PM | edited on 21 Jul 2022, 08:54 PM

This is not really a Telerik Grid problem.  This is a common serialization/deserialization problem.  The serialized version is not compatible with the current version.

Possible solutions:

  • If you embed your application version in the `TelerikGridKey`, the new version will not "find" the old version, it will look like a new user.

TelerikGridKey

  • Put a wrapper around what you are saving and embed the version into the wrapper.
  • Write a serializer/deserializer that will gracefully deserialize the old version into the new version as best it can.
Jerdobi
Top achievements
Rank 1
Iron
Iron
commented on 21 Jul 2022, 09:03 PM | edited

My workaround will be to make the local storage key unique by version of the TelerikGrid changes and just not restore it.  That said, I don't fully understand the schema (is it documented?) to try to shoehorn the deserialization as too complex and I can see where the GridState could easily save a hash to know it doesn't match the saved GridState and do no harm on a restore.
Timothy J
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 21 Jul 2022, 09:09 PM

>>My workaround will be to make the local storage key unique by version of the TelerikGrid changes and just not restore it.  <<

 

Correct, that's option 1 that I answered with.

0
Jerdobi
Top achievements
Rank 1
Iron
Iron
answered on 22 Jul 2022, 06:28 PM

This was the fix, to catch the failure and reset the gridstate.

 

Tags
Grid
Asked by
Jerdobi
Top achievements
Rank 1
Iron
Iron
Answers by
Timothy J
Top achievements
Rank 2
Bronze
Iron
Iron
Jerdobi
Top achievements
Rank 1
Iron
Iron
Share this question
or