From c039e19158d4327855902179cc175e5ee6872e19 Mon Sep 17 00:00:00 2001 From: capdiem Date: Wed, 28 Aug 2024 09:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(Sortable):=20the=20re-order?= =?UTF-8?q?=20should=20be=20triggered=20after=20the=20Order=20property=20v?= =?UTF-8?q?alue=20changes=20(#2120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sortable/MSortableProviderBase.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Masa.Blazor/Components/Sortable/MSortableProviderBase.cs b/src/Masa.Blazor/Components/Sortable/MSortableProviderBase.cs index 78d8d69442..52ff7dc9da 100644 --- a/src/Masa.Blazor/Components/Sortable/MSortableProviderBase.cs +++ b/src/Masa.Blazor/Components/Sortable/MSortableProviderBase.cs @@ -9,12 +9,7 @@ public abstract class MSortableProviderBase : MasaComponentBase, ISortabl [Parameter] [EditorRequired] public IEnumerable Items { get; set; } = Enumerable.Empty(); - [Parameter] - public List? Order - { - get => GetValue>(); - set => SetValue(value); - } + [Parameter] public List? Order { get; set; } [Parameter] public EventCallback> OrderChanged { get; set; } @@ -178,6 +173,7 @@ public bool Disabled private IEnumerable? _prevItems; private HashSet _prevItemKeys; private List _internalOrder; + private string[] _prevOrder = []; private DotNetObjectReference? _sortableJSInteropHandle; private SortableJSObjectReference? _jsObjectReference; @@ -205,8 +201,7 @@ protected override void RegisterWatchers(PropertyWatcher watcher) base.RegisterWatchers(watcher); watcher.Watch(nameof(Disabled), - val => { _jsObjectReference?.InvokeVoidAsync("option", "disabled", val); }) - .Watch>(nameof(Order), val => { _ = _jsObjectReference?.SortAsync(val, false); }); + val => { _jsObjectReference?.InvokeVoidAsync("option", "disabled", val); }); } protected override void OnParametersSet() @@ -232,6 +227,12 @@ protected override void OnParametersSet() SortByInternalOrder(); } } + + if (Order is not null && !_prevOrder.SequenceEqual(Order)) + { + _prevOrder = Order.ToArray(); + _ = _jsObjectReference?.SortAsync(Order, false); + } } protected override async Task OnAfterRenderAsync(bool firstRender)