DataGrid INotifyCollectionChanged support added

This commit is contained in:
Vladimir Enchev
2023-06-30 11:40:06 +03:00
parent ed9dbea34a
commit fbbcb58e3f
2 changed files with 32 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
@@ -117,12 +118,37 @@ namespace Radzen
if (_data != value)
{
_data = value;
if (_data != null && _data is INotifyCollectionChanged)
{
((INotifyCollectionChanged)_data).CollectionChanged += OnCollectionChanged;
}
OnDataChanged();
StateHasChanged();
}
}
}
/// <summary>
/// Called when INotifyCollectionChanged CollectionChanged is raised.
/// </summary>
protected virtual void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
}
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
if (_data != null && _data is INotifyCollectionChanged)
{
((INotifyCollectionChanged)_data).CollectionChanged -= OnCollectionChanged;
}
}
/// <summary>
/// Gets or sets the page size options.
/// </summary>

View File

@@ -1597,6 +1597,12 @@ namespace Radzen.Blazor
}
}
/// <inheritdoc />
protected override void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
InvokeAsync(Reload);
}
/// <summary>
/// Resets the DataGrid instance to initial state with no sorting, grouping and/or filtering.
/// </summary>