You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a page with a FluentDataGrid using ItemsProvide callback to fetch the data. I am storing in the session a JSON containing the values from the last GridItemsProviderRequest (SortBy column name, column SortDirection, and count), the current page of the pagination component. and other filters.
The idea is to get the last GridItemsProviderRequest values from the session when the user navigates back to the page, restoring the grid state (including sorted column, direction, current page, and other filters). I'm referencing the grid in code-behind (using the @ref property) and would like to set the sort by column, and direction. Still, I don't have access to the _sortByColumn and _sortByAscending from the FluentDataGrid.
Is there a way to use the reference object to set those values so that when the ItemProvider callback is called the GridItemsProviderRequest will have all the values restored from the session?
I would also appreciate any help on how to restore the last FluentDataGrid state from the session (I am using a browser session).
ItemsProvide callback:
private async ValueTask<GridItemsProviderResult<DeadLetterMessage>> DeadLetterMessagesProvider(
GridItemsProviderRequest<DeadLetterMessage> req)
{
_dataGrid?.SetLoadingState(true);
var queryParameters = new Dictionary<string, object?>();
if (!string.IsNullOrEmpty(RequestModel.Type))
{
queryParameters.Add("type", RequestModel.Type);
}
if (req.GetSortByProperties().Any())
{
queryParameters.Add("sortField", req.GetSortByProperties().First().PropertyName);
queryParameters.Add("sortDirection",
req.GetSortByProperties().First().Direction == SortDirection.Ascending ? 0 : 1);
}
queryParameters.Add("pageSize", req.Count);
queryParameters.Add("page", _pagination.CurrentPageIndex + 1);
// if _cachedQueryParameters dictionary is equal to queryParameters we will assume this is a
// request for the same data, and just keep the existing results. Clear that cache manually
// if you want to force re-retrieval.
if (_cachedQueryParameters.Count == queryParameters.Count &&
!_cachedQueryParameters.Except(queryParameters).Any())
{
return GridItemsProviderResult.From(_cachedItems, NumResults);
}
//reset the selected messages dictionary if the type filter changes.
var oldType = _cachedQueryParameters.GetValueOrDefault("type", "") ?? "";
var newType = queryParameters.GetValueOrDefault("type", "") ?? "";
if (!oldType.Equals(newType))
{
SelectedMessageIds = [];
}
var uri = $"{_caseManagementApiBaseUrl}/deadLetterMessage";
var url = NavManager.GetUriWithQueryParameters(uri, queryParameters);
DeadLetterMessageSearchResponse response;
try
{
response = await Http!.GetFromJsonAsync<DeadLetterMessageSearchResponse>(url, req.CancellationToken);
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
throw;
}
NumResults = response!.Count;
_cachedQueryParameters = queryParameters;
_cachedItems = new List<DeadLetterMessage>();
foreach (var item in response!.Items)
{
_cachedItems.Add(item);
SelectedMessageIds.TryAdd(item.Id, false);
}
await JS.InvokeVoidAsync("hljs.highlightAll");
if (_sessionStorageService is not null)
{
var queryParametersJson = JsonSerializer.Serialize(queryParameters);
await _sessionStorageService.SetValueAsync(QUERY_PARAMETERS_SESSION_NAME, queryParametersJson);
}
return GridItemsProviderResult.From(_cachedItems, NumResults);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a page with a FluentDataGrid using ItemsProvide callback to fetch the data. I am storing in the session a JSON containing the values from the last GridItemsProviderRequest (SortBy column name, column SortDirection, and count), the current page of the pagination component. and other filters.
The idea is to get the last GridItemsProviderRequest values from the session when the user navigates back to the page, restoring the grid state (including sorted column, direction, current page, and other filters). I'm referencing the grid in code-behind (using the @ref property) and would like to set the sort by column, and direction. Still, I don't have access to the _sortByColumn and _sortByAscending from the FluentDataGrid.
Is there a way to use the reference object to set those values so that when the ItemProvider callback is called the GridItemsProviderRequest will have all the values restored from the session?
I would also appreciate any help on how to restore the last FluentDataGrid state from the session (I am using a browser session).
ItemsProvide callback:
Beta Was this translation helpful? Give feedback.
All reactions