How to persist selected rows in DataGrid when paging while using LoadData event

My goal is to use LoadData event to do paging on the server.

I also need to persist rows selected.

However, when I go back to a page that has an item already selected and click on it. It adds it again to the rows selected.

Please advise.

What's your app, Blazor server or WASM? If you are using Blazor server and the data are coming from database you can use directly EF IQueriable as DataGrid Data instead LoadData. When using LoadData persisting selection can be tricky since every time you will get different data items with different hash code.

UPDATE: We've decided to add KeyProperty to the DataGrid component to improve item persistence in such cases. It will be available in our next update Monday:

1 Like

I'm using Blazor server.

I think the KeyProperty should work, because even though the hash may change the key id will be the same and that should resolve the issue while paging.

Thanks.

So on Monday all I have to do is re-import the nuget package?

You will need to update to the new version either by using Visual Studio NuGet manager UI or simply changing the version by edit the csproj. If you want to use always latest version of Radzen.Blazor you can use * symbol - check our demos for reference.