Reputation: 3131
I am using Blazor QuickGrid, bound to an ItemProvider
with virtualize enabled. I would like to persist the scrolled location of the the grid to the query string, and then have the grid start at that position when linked to.
I feel persisting pagination, sort, and filter is important so that when a user clicks off the grid page, then goes back in history, they are on the same page of data (unless data has changed). I am able to persist to the query string by calling this after items get provided:
private async Task OnGridItemsProvided()
{
var newQueryString = "state=" + JsonSerializer.Serialize(Provider.GridState);
var fullUri = new Uri(nav.Uri);
var baseUri = fullUri.GetLeftPart(UriPartial.Path);
nav.NavigateTo($"{baseUri}?{newQueryString}");
}
And can confirm the query string updates as I scroll the grid:
data/some?state={"StartIndex":93,"Count":50}
However, I can't find any way to force the grid to go to that location from code when a user lands on that.
What I would like to do is something like:
var stateJson = HttpUtility.ParseQueryString(new Uri(nav.Uri).Query).Get("state");
var state = JsonSerializer.Deserialize<GridState>(stateJson);
grid.Virtualization.SetStartIndex(state.Skip)
I tried using grid.Pagination.SetCurrentPageIndexAsync
, but when pagination is set, the grid no longer virtualizes.
Upvotes: 0
Views: 57