Skip to content

Commit e228291

Browse files
committed
fix grid state timing issue
1 parent 904ff2f commit e228291

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/LoreSoft.Blazor.Controls/Data/DataGrid.razor.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public partial class DataGrid<TItem> : DataComponentBase<TItem>
202202
/// </summary>
203203
public List<DataColumn<TItem>> Columns { get; } = [];
204204

205+
/// <summary>
206+
/// Gets the most recently saved state of the data grid, if available.
207+
/// </summary>
208+
public DataGridState? LastGridState { get; private set; }
209+
205210
/// <summary>
206211
/// Gets a value indicating whether the column picker panel is open.
207212
/// The column picker allows users to show/hide columns that have <see cref="DataColumn{TItem}.Hideable"/> set to true.
@@ -966,6 +971,9 @@ private async Task ResetStateAsync(
966971
// notify subscribers to reset their own state
967972
StateResetting?.Invoke();
968973

974+
// clear cached state
975+
LastGridState = null;
976+
969977
// refresh sort picker state if needed
970978
UpdateSortPickerState();
971979

@@ -978,6 +986,7 @@ private async Task ResetStateAsync(
978986
{
979987
_isResetting = false;
980988
}
989+
981990
}
982991

983992
/// <summary>
@@ -1004,9 +1013,12 @@ private async Task LoadStateAsync()
10041013
return;
10051014
}
10061015

1007-
if (state is null)
1016+
if (state is null || state == LastGridState)
10081017
return;
10091018

1019+
// cache loaded state to prevent redundant loads and detect changes on subsequent loads
1020+
LastGridState = state;
1021+
10101022
// restore filters
10111023
if (state.Query?.Filters.Count > 0)
10121024
{
@@ -1091,6 +1103,9 @@ private async Task SaveStateAsync()
10911103
// allow subscribers to add their own state to the extensions bag
10921104
StateSaving?.Invoke(state);
10931105

1106+
// cache loaded state to prevent redundant loads and detect changes on subsequent loads
1107+
LastGridState = state;
1108+
10941109
try
10951110
{
10961111
await StorageService.SetItemAsync(

src/LoreSoft.Blazor.Controls/Data/DataGridToolbar.razor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ protected override void OnParametersSet()
181181
CurrentGrid.StateLoaded += HandleStateLoaded;
182182
CurrentGrid.StateResetting += HandleStateResetting;
183183
}
184+
185+
if (CurrentGrid?.LastGridState != null)
186+
HandleStateLoaded(CurrentGrid.LastGridState);
184187
}
185188

186189
/// <inheritdoc />

src/LoreSoft.Blazor.Controls/Query/QueryBuilderFilter.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected void OperatorChanged()
7272
/// Gets a value indicating whether the value input should be shown for the current operator.
7373
/// </summary>
7474
protected bool ShowValueInput
75-
=> Filter.Operator is not QueryOperators.IsNull or QueryOperators.IsNotNull;
75+
=> Filter.Operator is not (QueryOperators.IsNull or QueryOperators.IsNotNull);
7676

7777
/// <summary>
7878
/// Removes this filter from its parent group and refreshes the query builder.

0 commit comments

Comments
 (0)