Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datagrid] Page reload issue when using SaveStateInUrl #2987

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.SaveStateInUrl">
<summary>
Gets or sets a value indicating whether the grid should save its paging state in the URL.
<para>This is an **experimental** feature, which might cause unwanted jumping in the page when you change something in the grid.</para>
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.SaveStatePrefix">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
RowClass="@rowClass"
RowStyle="@rowStyle"
HeaderCellAsButtonWithMenu="true"
ColumnResizeLabels="@customLabels"
SaveStateInUrl="true"
SaveStatePrefix="g1">
ColumnResizeLabels="@customLabels">
<TemplateColumn Tooltip="true" TooltipText="@(c => "Flag of " + c.Name)" Title="Rank" SortBy="@rankSort" Align="Align.Center" InitialSortDirection="SortDirection.Ascending" IsDefaultSortColumn=true>
<img class="flag" src="_content/FluentUI.Demo.Shared/flags/@(context.Code).svg" alt="Flag of @(context.Code)" />
</TemplateColumn>
Expand Down
9 changes: 3 additions & 6 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve

/// <summary>
/// Gets or sets a value indicating whether the grid should save its paging state in the URL.
/// <para>This is an experimental feature, which might cause unwanted jumping in the page when you change something in the grid.</para>
/// </summary>
[Parameter]
public bool SaveStateInUrl { get; set; }
Expand Down Expand Up @@ -425,6 +426,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
}
}

SaveStateToQueryString();

if (_checkColumnOptionsPosition && _displayOptionsForColumn is not null)
{
_checkColumnOptionsPosition = false;
Expand Down Expand Up @@ -981,10 +984,4 @@ public async Task ResetColumnWidthsAsync()
await Module.InvokeVoidAsync("resetColumnWidths", _gridReference);
}
}

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
SaveStateToQueryString();
}
}
Loading