Skip to content

Commit

Permalink
🐛 fix(DataTable): adding or deleting items doesn't refresh the table
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Jul 2, 2024
1 parent e6cd691 commit 321d96e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Masa.Blazor/Components/Data/MData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ protected override void RegisterWatchers(PropertyWatcher watcher)
private bool _prevDisableFiltering;
private int _prevServerItemsLength;
private IEnumerable<ItemValue<TItem>>? _prevItemValues;
private IEnumerable<TItem>? _prevItems;
private HashSet<TItem>? _prevItems;
private string? _prevSearch;
private int _prevPageCount;

Expand All @@ -359,7 +359,7 @@ private void CheckForUpdates()
needUpdateComputedItems |= CheckAndUpdate(ref _prevServerItemsLength, ServerItemsLength);
needUpdateComputedItems |= CheckAndUpdate(ref _prevDisableFiltering, DisableFiltering);
needUpdateComputedItems |= CheckAndUpdate(ref _prevItemValues, ItemValues);
needUpdateComputedItems |= CheckAndUpdate(ref _prevItems, Items);
needUpdateComputedItems |= CheckItemsAndUpdate(ref _prevItems, Items);
needUpdateComputedItems |= CheckAndUpdate(ref _prevSearch, Search);

if (needUpdateComputedItems)
Expand All @@ -376,6 +376,26 @@ private bool CheckAndUpdate<T>(ref T prevValue, T currentValue)
return true;
}

private bool CheckItemsAndUpdate<T>(ref HashSet<T>? prevValue, IEnumerable<T>? currentValue)
{
if (prevValue == null && currentValue == null) return false;
if (prevValue == null || currentValue == null)
{
prevValue = currentValue != null ? [..currentValue] : null;
return true;
}

var currentSet = new HashSet<T>(currentValue);

if (!prevValue.SetEquals(currentSet))
{
prevValue = currentSet;
return true;
}

return false;
}

protected IList<TValue> WrapperInArray<TValue>(OneOf<TValue, IList<TValue>> val)
{
if (val.Value == null)
Expand Down

0 comments on commit 321d96e

Please sign in to comment.