The render handle is not yet assigned

@if (_isLoading)
{
  <LoadingScreen/>
}
else
{
  <PageTitle>@_pageTitle</PageTitle>
  <div class="mb-2">
    <h3>@Localizer["CheckSurveysOverview"]</h3>
  </div>
  <div>
    <RadzenDataGrid Id="surveytable" @ref="_ongoingGrid" Data="@_ongoingSurveys" TItem="CheckSurveysOverviewModel" @bind-Settings="@OngoingSettings"
                    AllowColumnResize="true" AllowAlternatingRows="true" AllowPaging="true" PageSize="10" ExpandMode="DataGridExpandMode.Single"
                    AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                    RowClick="OnSurveyRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow">
      <EmptyTemplate>
        <p class="emptyText">@Localizer["NoData"]</p>
      </EmptyTemplate>
      <Template Context="survey">
        <RadzenTabs SelectedIndex="@_selectedTabIndex" Change=OnTabChange>
          <Tabs>
            <RadzenTabsItem Text="@Localizer["CompletedSurveys"]">
              <RadzenDataGrid Data="@survey.OngoingSurveyDetails.Where(s => s.SurveyAnswerStatus == SurveyAnswerStatus.Submitted)" TItem="OngoingSurveyDetailModel"
                              Density="Density.Compact" AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                              RowClick="OnSurveyAnswerRowClick">
                <EmptyTemplate>
                  <p class="emptyText">@Localizer["NoData"]</p>
                </EmptyTemplate>
                <Columns>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="ClubName" Filterable="true" Title="@_clubName" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="SubmitDate" Filterable="true" Title="@Localizer["SubmitDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="OverallScore" Filterable="true" Title="@Localizer["OverallScore"]" TextAlign="TextAlign.Center"/>
                  @if (Configuration.GetValue<bool>("ClubChat"))
                  {
                    <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="true" Title="@Localizer["Messages"]" Width="10px" TextAlign="TextAlign.Center">
                      <Template Context="data">
                        <RadzenBadge IsPill="true" Variant="Variant.Outlined" BadgeStyle="BadgeStyle.Danger" Text="@data.NewMessagesCount.ToString()" Visible="@(data.NewMessagesCount != 0)"/>
                      </Template>
                    </RadzenDataGridColumn>
                  }
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="10px" TextAlign="TextAlign.Center" Visible="@survey.OngoingSurveyDetails.Any(s => s.SurveyAnswerStatus == SurveyAnswerStatus.Submitted)">
                    <Template Context="data">
                      @GetValidatedQuestionsCount(data)
                    </Template>
                  </RadzenDataGridColumn>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
                    <Template Context="data">
                      <RadzenButton title="@Localizer["Reopen"]" Click="@(() => { _isReopen = true; return EditDueDateOrReopenSurveyAnswer(data); })" @onclick:stopPropagation Icon="assignment_return" Style="color: inherit" Id="IconOnlyButton"/>
                    </Template>
                  </RadzenDataGridColumn>
                </Columns>
              </RadzenDataGrid>
            </RadzenTabsItem>
            <RadzenTabsItem Text="@Localizer["PendingSurveys"]">
              <RadzenDataGrid Data="@survey.OngoingSurveyDetails.Where(s => s.SurveyAnswerStatus != SurveyAnswerStatus.Submitted)" TItem="OngoingSurveyDetailModel"
                              Density="Density.Compact" AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                              RowClick="OnSurveyAnswerRowClick">
                <EmptyTemplate>
                  <p class="emptyText">@Localizer["NoData"]</p>
                </EmptyTemplate>
                <Columns>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="ClubName" Filterable="true" Title="@_clubName" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="true" Title="@Localizer["Status"]" TextAlign="TextAlign.Center">
                    <Template Context="data">
                      @Localizer[GetStatusString(data.SurveyAnswerStatus)]
                    </Template>
                  </RadzenDataGridColumn>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
                    <Template Context="data">
                      <RadzenButton title="@Localizer["EditDueDate"]" Click="@(() => { return EditDueDateOrReopenSurveyAnswer(data); })" @onclick:stopPropagation Icon="edit_calendar" Style="color: inherit" Id="IconOnlyButton"/>
                    </Template>
                  </RadzenDataGridColumn>
                </Columns>
              </RadzenDataGrid>
            </RadzenTabsItem>
          </Tabs>
        </RadzenTabs>
      </Template>
      <Columns>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="Title" Filterable="true" Title="@Localizer["Title"]" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="SendDate" Filterable="true" Title="@Localizer["SendDate"]" Width="10px" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" Width="10px" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Filterable="false" Sortable="false" Width="10px" TextAlign="TextAlign.Center">
          <Template Context="survey">
            @GetSurveyCount(survey)
          </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
          <Template Context="data">
            <RadzenButton title="@Localizer["RecalculateScores"]" Click="@(() => { return ConfirmRecalculateSurveyAnswers(data.OngoingSurveyDetails); })" @onclick:stopPropagation Icon="calculate" IconColor="@Colors.Black" Id="IconOnlyButton"/>
            @if (Configuration.GetValue<bool>("ExportToCsv"))
            {
              <RadzenButton title="@Localizer["ExportCsv"]" Click="@(() => { return ExportDataToCsv(data); })" @onclick:stopPropagation Image="img/CSV96.png" Id="IconOnlyButton"/>
            }
          </Template>
        </RadzenDataGridColumn>
      </Columns>
    </RadzenDataGrid>
  </div>
}

@code {
  
  [CascadingParameter (Name="isTest")]
  public bool isTest{ get; set; }
  
  private string _pageTitle;
  private string _clubName;
  private bool _isSetData;
  private bool _isLoading = true;
  private bool _isReopen;
  private Guid _expandedRowId;
  private bool _expandRowOnInit;
  private int _selectedTabIndex;

  IEnumerable<CheckSurveysOverviewModel> _ongoingSurveys = new List<CheckSurveysOverviewModel>();
  RadzenDataGrid<CheckSurveysOverviewModel?> _ongoingGrid = new();

  DataGridSettings? _ongoingSettings;

  private DataGridSettings? OngoingSettings
  {
    get => _ongoingSettings;
    set
    {
      if (_isSetData)
      {
        _isSetData = false;
        return;
      }

      _ongoingSettings = value;
      InvokeAsync(SaveOngoingSettingsAsync);
    }
  }

  protected override async Task OnInitializedAsync()
  {
    await base.OnInitializedAsync();
    await SetDataAsync();
    _isSetData = false;
    _isLoading = false;
    _pageTitle = $"{(isTest ? "Test" : "Production")} - {Localizer["CheckSurveysOverview"]}";
    _clubName = isTest? Localizer["Respondent"] : Localizer["Club"];
  }

  private async Task SetDataAsync()
  {
    var result = await GetOngoingSurveys.QueryAsync();

    _ongoingSurveys = result.GroupBy(item => item.SurveyId)
      .Select(survey => new CheckSurveysOverviewModel
      {
        SurveyId = survey.Key,
        Title = survey.First().Title,
        SendDate = survey.First().SendDate,
        DueDate = survey.First().DueDate,
        OngoingSurveyDetails = survey
          .Select(item => new OngoingSurveyDetailModel
          {
            ClubName = item.ClubName,
            SubmitDate = item.SubmitDate,
            DueDate = item.DueDate,
            SurveyAnswerId = item.SurveyAnswerId,
            SurveyAnswerStatus = item.SurveyAnswerStatus,
            AnswerList = item.AnswerList,
            OverallScore = item.OverallScore,
            NewMessagesCount = item.NewMessagesCount
          }).ToList()
      }).ToList();
    _isSetData = true;
  }

  protected override async Task OnAfterRenderAsync(bool firstRender)
  {
    if (firstRender)
    {
      await LoadOngoingSettingsAsync();
      await LoadOngoingGridStateAsync();
    }
  }

  private async Task LoadOngoingGridStateAsync()
  {
    await LoadExpandedRowAsync();
    if (_expandRowOnInit)
    {
      await _ongoingGrid.ExpandRow(_ongoingSurveys.FirstOrDefault(s => s.SurveyId == _expandedRowId));
      _expandRowOnInit = false;
    }

    await LoadSelectedTabAsync();
    await _ongoingGrid.Reload();
    StateHasChanged();
  }

  private async Task SaveOngoingSettingsAsync()
  {
    await Task.CompletedTask;
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.setItem", "OngoingSettings", JsonSerializer.Serialize(OngoingSettings));
  }

  private async Task LoadOngoingSettingsAsync()
  {
    await Task.CompletedTask;
    var result = await JsRuntime.InvokeAsync<string>("window.sessionStorage.getItem", "OngoingSettings");
    if (!string.IsNullOrEmpty(result))
    {
      _ongoingSettings = JsonSerializer.Deserialize<DataGridSettings>(result);
    }
  }
}

When I open my page I get the following error:

System.InvalidOperationException: The render handle is not yet assigned.
at Microsoft.AspNetCore.Components.RenderHandle.ThrowNotInitialized()
at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
at Radzen.Blazor.RadzenDataGrid1.ReloadInternal() at Radzen.Blazor.RadzenDataGrid1.Reload()
at WebApp.Pages.Federation.Overviews.CheckSurveysOverview.LoadOngoingGridStateAsync() in C:\WebApp\Pages\Federation\Overviews\CheckSurveysOverview.razor:line 218
at WebApp.Pages.Federation.Overviews.CheckSurveysOverview.OnAfterRenderAsync(Boolean firstRender) in C:\WebApp\Pages\Federation\Overviews\CheckSurveysOverview.razor:line 204
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Can you tell me how to solve this... It used to work but now I have like a really big survey that has been added.

Regards,
Tino

I haven't seen such error before and according to the stack trace the exception is raised by calling DataGrid Reload() method in LoadOngoingGridStateAsync() on first render. In our demo this is not needed and we use just StateHasChanged():

Maybe you can try the approach from our LoadData demo with LoadSettings callback:

Hi,

Thnak you for your quick reply. I'm refactoring my code base to use the LoadData approach over the oninitialized approach. However, ExpandRow is not part of GridSettings if I'm not mistaken...

How do I handle that?

Kind regards,
Tino

Hi,

I've integrated the LoadData approach in my application, but I think I must be missing something.
My app runs the LoadGridStateAsync on firstrender properly, however my LoadDataAsync is not being called.
Any idea why?

@page "/CheckSurveysOverview"
@using Presentation.SurveyFeatures.Federation.Interface
@using Client.WebApp.Pages.Federation.Models.Overviews
@using Client.WebApp.Pages.Shared
@using Vocabulary
@using Microsoft.Extensions.Localization
@using System.Text.Json
@using Application.Survey.ExportSurveyData
@using Application.SurveyAnswer.Federation.EditDueDateOrReopen
@using Application.SurveyAnswer.Federation.ScoreCalculation
@using Client.WebApp.Pages.Federation.Survey.Dialogs

@inject DialogService DialogService
@inject IConfiguration Configuration
@inject IJSRuntime JsRuntime
@inject IStringLocalizer<Resource> Localizer
@inject NavigationManager NavigationManager
@inject NotificationService NotificationService
@inject EditDueDateOrReopen EditDueDateOrReopen
@inject GetOngoingSurveys GetOngoingSurveys
@inject GetSurveyData GetSurveyData
@inject CalculateScores CalculateScores

@if (_isLoading)
{
  <LoadingScreen/>
}
else
{
  <PageTitle>@_pageTitle</PageTitle>
  <div class="mb-2">
    <h3>@Localizer["CheckSurveysOverview"]</h3>
  </div>
  <div>
    <RadzenDataGrid Id="surveytable" @ref="_ongoingGrid" Data="@_ongoingSurveys" TItem="CheckSurveysOverviewModel" ExpandMode="DataGridExpandMode.Single"
                    @bind-Settings="@OngoingSettings" LoadSettings="@LoadSettings"AllowColumnResize="true" AllowAlternatingRows="true" AllowPaging="true" 
                    PageSize="10" AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                    IsLoading=@_isLoading LoadData=@LoadDataAsync RowClick="OnSurveyRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow">
      <EmptyTemplate>
        <p class="emptyText">@Localizer["NoData"]</p>
      </EmptyTemplate>
      <Template Context="survey">
        <RadzenTabs SelectedIndex="@_selectedTabIndex" Change=OnTabChange>
          <Tabs>
            <RadzenTabsItem Text="@Localizer["CompletedSurveys"]">
              <RadzenDataGrid Data="@survey.OngoingSurveyDetails.Where(s => s.SurveyAnswerStatus == SurveyAnswerStatus.Submitted)" TItem="OngoingSurveyDetailModel"
                              Density="Density.Compact" AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                              RowClick="OnSurveyAnswerRowClick">
                <EmptyTemplate>
                  <p class="emptyText">@Localizer["NoData"]</p>
                </EmptyTemplate>
                <Columns>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="ClubName" Filterable="true" Title="@_clubName" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="SubmitDate" Filterable="true" Title="@Localizer["SubmitDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="OverallScore" Filterable="true" Title="@Localizer["OverallScore"]" TextAlign="TextAlign.Center"/>
                  @if (Configuration.GetValue<bool>("ClubChat"))
                  {
                    <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="true" Title="@Localizer["Messages"]" Width="10px" TextAlign="TextAlign.Center">
                      <Template Context="data">
                        <RadzenBadge IsPill="true" Variant="Variant.Outlined" BadgeStyle="BadgeStyle.Danger" Text="@data.NewMessagesCount.ToString()" Visible="@(data.NewMessagesCount != 0)"/>
                      </Template>
                    </RadzenDataGridColumn>
                  }
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="10px" TextAlign="TextAlign.Center" Visible="@survey.OngoingSurveyDetails.Any(s => s.SurveyAnswerStatus == SurveyAnswerStatus.Submitted)">
                    <Template Context="data">
                      @GetValidatedQuestionsCount(data)
                    </Template>
                  </RadzenDataGridColumn>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
                    <Template Context="data">
                      <RadzenButton title="@Localizer["Reopen"]" Click="@(() => { _isReopen = true; return EditDueDateOrReopenSurveyAnswer(data); })" @onclick:stopPropagation Icon="assignment_return" Style="color: inherit" Id="IconOnlyButton"/>
                    </Template>
                  </RadzenDataGridColumn>
                </Columns>
              </RadzenDataGrid>
            </RadzenTabsItem>
            <RadzenTabsItem Text="@Localizer["PendingSurveys"]">
              <RadzenDataGrid Data="@survey.OngoingSurveyDetails.Where(s => s.SurveyAnswerStatus != SurveyAnswerStatus.Submitted)" TItem="OngoingSurveyDetailModel"
                              Density="Density.Compact" AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                              RowClick="OnSurveyAnswerRowClick">
                <EmptyTemplate>
                  <p class="emptyText">@Localizer["NoData"]</p>
                </EmptyTemplate>
                <Columns>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="ClubName" Filterable="true" Title="@_clubName" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" TextAlign="TextAlign.Center"/>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="true" Title="@Localizer["Status"]" TextAlign="TextAlign.Center">
                    <Template Context="data">
                      @Localizer[GetStatusString(data.SurveyAnswerStatus)]
                    </Template>
                  </RadzenDataGridColumn>
                  <RadzenDataGridColumn TItem="OngoingSurveyDetailModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
                    <Template Context="data">
                      <RadzenButton title="@Localizer["EditDueDate"]" Click="@(() => { return EditDueDateOrReopenSurveyAnswer(data); })" @onclick:stopPropagation Icon="edit_calendar" Style="color: inherit" Id="IconOnlyButton"/>
                    </Template>
                  </RadzenDataGridColumn>
                </Columns>
              </RadzenDataGrid>
            </RadzenTabsItem>
          </Tabs>
        </RadzenTabs>
      </Template>
      <Columns>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="Title" Filterable="true" Title="@Localizer["Title"]" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="SendDate" Filterable="true" Title="@Localizer["SendDate"]" Width="10px" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Property="DueDate" Filterable="true" Title="@Localizer["DueDate"]" Width="10px" TextAlign="TextAlign.Center"/>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Filterable="false" Sortable="false" Width="10px" TextAlign="TextAlign.Center">
          <Template Context="survey">
            @GetSurveyCount(survey)
          </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="CheckSurveysOverviewModel" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center" Title="@Localizer["Actions"]">
          <Template Context="data">
            <RadzenButton title="@Localizer["RecalculateScores"]" Click="@(() => { return ConfirmRecalculateSurveyAnswers(data.OngoingSurveyDetails); })" @onclick:stopPropagation Icon="calculate" IconColor="@Colors.Black" Id="IconOnlyButton"/>
            @if (Configuration.GetValue<bool>("ExportToCsv"))
            {
              <RadzenButton title="@Localizer["ExportCsv"]" Click="@(() => { return ExportDataToCsv(data); })" @onclick:stopPropagation Image="img/CSV96.png" Id="IconOnlyButton"/>
            }
          </Template>
        </RadzenDataGridColumn>
      </Columns>
    </RadzenDataGrid>
  </div>
}

@code {
  
  [CascadingParameter (Name="Alternate")]
  public bool Alternate { get; set; }
  
  private string _pageTitle;
  private string _clubName;
  private bool _isSetData;
  private bool _isLoading;
  private bool _isReopen;
  private Guid _expandedRowId;
  private bool _expandRowOnInit;
  private int _selectedTabIndex;

  IEnumerable<CheckSurveysOverviewModel> _ongoingSurveys = new List<CheckSurveysOverviewModel>();
  RadzenDataGrid<CheckSurveysOverviewModel?> _ongoingGrid = new();

  DataGridSettings? _ongoingSettings;

  private DataGridSettings? OngoingSettings
  {
    get => _ongoingSettings;
    set
    {
      if (_isSetData)
      {
        _isSetData = false;
        return;
      }

      _ongoingSettings = value;
      InvokeAsync(SaveOngoingSettingsAsync);
    }
  }
  
  private async Task LoadDataAsync()
  {
    _isLoading = true;

    await Task.Yield();

    var result = await GetOngoingSurveys.QueryAsync();

    _ongoingSurveys = result.GroupBy(item => item.SurveyId)
      .Select(survey => new CheckSurveysOverviewModel
      {
        SurveyId = survey.Key,
        Title = survey.First().Title,
        SendDate = survey.First().SendDate,
        DueDate = survey.First().DueDate,
        OngoingSurveyDetails = survey
          .Select(item => new OngoingSurveyDetailModel
          {
            ClubName = item.ClubName,
            SubmitDate = item.SubmitDate,
            DueDate = item.DueDate,
            SurveyAnswerId = item.SurveyAnswerId,
            SurveyAnswerStatus = item.SurveyAnswerStatus,
            AnswerList = item.AnswerList,
            OverallScore = item.OverallScore,
            NewMessagesCount = item.NewMessagesCount
          }).ToList()
      }).ToList();

    _isLoading = false;
    _pageTitle = $"{(Alternate ? "Alternate" : "Original")} - {Localizer["CheckSurveysOverview"]}";
    _clubName = Alternate ? Localizer["Respondent"] : Localizer["Club"];
    
    if (_expandRowOnInit)
    {
      await _ongoingGrid.ExpandRow(_ongoingSurveys.FirstOrDefault(s => s.SurveyId == _expandedRowId));
      _expandRowOnInit = false;
    }
  }

  protected override async Task OnAfterRenderAsync(bool firstRender)
  {
    if (firstRender)
    {
      await LoadOngoingGridStateAsync();
    }
  }
  
  private async Task LoadOngoingGridStateAsync()
  {
    var ongoingSettings = await JsRuntime.InvokeAsync<string>("window.sessionStorage.getItem", "OngoingSettings");
    if (!string.IsNullOrEmpty(ongoingSettings))
    {
      _ongoingSettings = JsonSerializer.Deserialize<DataGridSettings>(ongoingSettings);
    }
    var expandedRow = await JsRuntime.InvokeAsync<string>("window.sessionStorage.getItem", "ExpandedRow");
    _expandedRowId = !string.IsNullOrEmpty(expandedRow) ? JsonSerializer.Deserialize<Guid>(expandedRow) : Guid.Empty;

    if (_expandedRowId != Guid.Empty)
    {
      _expandRowOnInit = true;
    }
    var selectedTab = await JsRuntime.InvokeAsync<string>("window.sessionStorage.getItem", "SelectedTab");
    _selectedTabIndex = !string.IsNullOrEmpty(selectedTab) ? int.Parse(selectedTab) : 0;
  }
  
  void LoadSettings(DataGridLoadSettingsEventArgs args)
  {
    if (_ongoingSettings != null)
    {
      args.Settings = _ongoingSettings;
    }
  }

  private async Task SaveOngoingSettingsAsync()
  {
    await Task.CompletedTask;
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.setItem", "OngoingSettings", JsonSerializer.Serialize(OngoingSettings));
  }

  private async void OnSurveyRowClick(DataGridRowMouseEventArgs<CheckSurveysOverviewModel> surveyRow)
  {
    await _ongoingGrid.ExpandRow(surveyRow.Data);
  }

  private async Task SaveExpandedRow(CheckSurveysOverviewModel row)
  {
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.setItem", "ExpandedRow", JsonSerializer.Serialize(row.SurveyId));
    if (_expandRowOnInit) return;
    await ResetTab();
  }

  private async Task RemoveExpandedRow(CheckSurveysOverviewModel row)
  {
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.removeItem", "ExpandedRow");
    if (_expandRowOnInit) return;
    await ResetTab();
  }

  private async Task OnTabChange(int index)
  {
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.setItem", "SelectedTab", $"{index}");
  }

  private async Task ResetTab()
  {
    _selectedTabIndex = 0;
    await JsRuntime.InvokeVoidAsync("window.sessionStorage.setItem", "SelectedTab", $"{_selectedTabIndex}");
    await _ongoingGrid.Reload();
    StateHasChanged();
  }

  private async Task LoadSelectedTabAsync()
  {
    var result = await JsRuntime.InvokeAsync<string>("window.sessionStorage.getItem", "SelectedTab");
    _selectedTabIndex = !string.IsNullOrEmpty(result) ? int.Parse(result) : 0;
  }

  private string GetSurveyCount(CheckSurveysOverviewModel survey)
  {
    var submittedCount = survey.OngoingSurveyDetails.Count(detail => detail.SurveyAnswerStatus == SurveyAnswerStatus.Submitted);
    var totalCount = survey.OngoingSurveyDetails.Count;

    return $"{submittedCount} / {totalCount} {Localizer["Received"]}";
  }

  private async Task ConfirmRecalculateSurveyAnswers(IEnumerable<OngoingSurveyDetailModel> ongoingSurveys)
  {
    var result = await DialogService.Confirm(Localizer["ConfirmRecalculateSurveyAnswers"], Localizer["RecalculateScores"],
      new ConfirmOptions { OkButtonText = Localizer["Yes"], CancelButtonText = Localizer["No"] });

    if (result != true) return;
    await RecalculateSurveyAnswers(ongoingSurveys);
  }

  private async Task RecalculateSurveyAnswers(IEnumerable<OngoingSurveyDetailModel> ongoingSurveys)
  {
    try
    {
      await CalculateScores.HandleAsync(new CalculateScoresCommand
      {
        SurveyAnswerIds = ongoingSurveys.Select(detail => detail.SurveyAnswerId).ToList()
      });
      NotificationService.Notify(new NotificationMessage
      {
        Severity = NotificationSeverity.Success,
        Detail = Localizer["RecalculateSuccess"],
        Duration = 2000
      });
      await LoadDataAsync();
    }
    catch (Exception ex)
    {
      if (ex.Message == "No Clubs Found")
      {
      }
      else
      {
        NotificationService.Notify(new NotificationMessage
        {
          Severity = NotificationSeverity.Error,
          Detail = Localizer["RecalculateFailure"],
          Duration = 2000
        });
      }
    }
  }

  private async Task ExportDataToCsv(CheckSurveysOverviewModel surveyModel)
  {
    try
    {
      var bytes = await GetSurveyData.HandleAsync(new GetSurveyDataCommand
      {
        SurveyId = surveyModel.SurveyId
      });

      var fileName = $"{surveyModel.Title} - {DateTime.UtcNow.AddHours(1):ddMMyyyy_HHmmss}.csv";

      var stream = new MemoryStream();
      stream.Write(bytes, 0, bytes.Length);
      stream.Seek(0, SeekOrigin.Begin);
      using var streamRef = new DotNetStreamReference(stream, true);

      await JsRuntime.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
      await InvokeAsync(StateHasChanged);
    }
    catch (Exception e)
    {
      NotificationService.Notify(new NotificationMessage
      {
        Severity = NotificationSeverity.Error,
        Summary = Localizer["CsvExportFailure"],
        Detail = e.Message,
        Duration = -1
      });
    }
  }

  private object GetValidatedQuestionsCount(OngoingSurveyDetailModel surveyDetail)
  {
    if (string.IsNullOrEmpty(surveyDetail.AnswerList)) return $"{Localizer["NotYetValidated"]}";

    var answerList = surveyDetail.AnswerList.Split(',').ToList();
    var validatedCount = answerList.Count(b => b == "1");
    if (validatedCount == 0) return $"{Localizer["NotYetValidated"]}";

    var totalCount = answerList.Count;
    return $"{validatedCount} / {totalCount} {Localizer["AnswersValidated"]}";
  }

  private static string GetStatusString(SurveyAnswerStatus surveyAnswerStatus)
  {
    return surveyAnswerStatus switch
    {
      SurveyAnswerStatus.New => "NewStatus",
      SurveyAnswerStatus.Incomplete => "IncompleteStatus",
      SurveyAnswerStatus.Submitted => "SubmittedStatus",
      _ => throw new ArgumentOutOfRangeException(nameof(surveyAnswerStatus), surveyAnswerStatus, "SurveyAnswerStatus unknown")
    };
  }

  private void OnSurveyAnswerRowClick(DataGridRowMouseEventArgs<OngoingSurveyDetailModel> selectedSurveyAnswerRow)
  {
    NavigationManager.NavigateTo($"/OngoingSurveyDetail/{selectedSurveyAnswerRow.Data.SurveyAnswerId}");
  }

  private async Task EditDueDateOrReopenSurveyAnswer(OngoingSurveyDetailModel ongoingSurveyDetail)
  {
    var result = await DialogService.OpenAsync<EditDueDateOrReopenDialog>(Localizer[_isReopen ? "ReopenSurveyAnswer" : "EditDueDate"],
      new Dictionary<string, object> { { "IsReopen", _isReopen }, { "OngoingSurveyDueDate", DateTime.Parse(ongoingSurveyDetail.DueDate) } }, new DialogOptions
      {
        Width = "700px",
        Resizable = true,
        Draggable = true,
        ShowClose = false
      });


    if (result == null)
    {
      _isReopen = false;
      return;
    }

    var updatedDueDate = (DateTime)result;

    try
    {
      await EditDueDateOrReopen.HandleAsync(new EditDueDateOrReopenCommand
      {
        Id = ongoingSurveyDetail.SurveyAnswerId,
        DueDate = updatedDueDate,
        IsReopen = _isReopen
      });
      NotificationService.Notify(new NotificationMessage
      {
        Severity = NotificationSeverity.Success,
        Detail = Localizer[_isReopen ? "ReopenSuccess" : "EditDueDateSuccess"],
        Duration = 2000
      });
      _isReopen = false;
      await InvokeAsync(StateHasChanged);
    }
    catch (Exception ex)
    {
      if (ex.Message == "No Clubs Found")
      {
      }
      else
      {
        NotificationService.Notify(new NotificationMessage
        {
          Severity = NotificationSeverity.Error,
          Detail = Localizer[_isReopen ? "ReopenFailure" : "EditDueDateFailure"],
          Duration = 2000
        });
      }
    }
  }
}

Hi @TinoS,

Please check the forum FAQ and format your code. Your post is unreadable at the moment.

Hi,

Yes I noticed I just edited it into a readable version. Is it ok now?

Rgds,
Tino

Hi,

My mistake. I found the issue, I didn't make my IEnumerable nullable.

rgds,
Tino