diff --git a/COMETwebapp/Components/ParameterEditor/ParameterTable.razor b/COMETwebapp/Components/ParameterEditor/ParameterTable.razor index 649a4e8a..0005ed75 100644 --- a/COMETwebapp/Components/ParameterEditor/ParameterTable.razor +++ b/COMETwebapp/Components/ParameterEditor/ParameterTable.razor @@ -66,7 +66,7 @@ public partial class ParameterTable { + /// + /// The + /// + private readonly ParameterBaseRowViewModelComparer comparer = new(); + /// /// to close the popup editor /// private EventCallback closeEditor; /// - /// The + /// The sorted collection of /// - private readonly ParameterBaseRowViewModelComparer comparer = new(); + private ReadOnlyObservableCollection sortedCollection; /// /// Gets or sets the @@ -56,6 +65,11 @@ public partial class ParameterTable [Parameter] public IParameterTableViewModel ViewModel { get; set; } + /// + /// Gets the current view model hash code to compare with new ones + /// + public int ViewModelHashCode { get; set; } + /// /// Gets or sets the grid control that is being customized. /// @@ -75,6 +89,34 @@ protected override void OnInitialized() this.closeEditor = new EventCallbackFactory().Create(this, () => { this.ViewModel.IsOnEditMode = false; }); } + /// + /// Method invoked when the component has received parameters from its parent in + /// the render tree, and the incoming values have been assigned to properties. + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + if (this.ViewModel.GetHashCode() == this.ViewModelHashCode) + { + return; + } + + if (this.ViewModelHashCode != 0) + { + var latestViewModelRowsSubscription = this.Disposables.Last(); + latestViewModelRowsSubscription.Dispose(); + this.Disposables.Remove(latestViewModelRowsSubscription); + } + + this.Disposables.Add(this.ViewModel.Rows.Connect() + .Sort(this.comparer) + .Bind(out this.sortedCollection) + .Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); + + this.ViewModelHashCode = this.ViewModel.GetHashCode(); + } + /// /// Customizes the table rows /// @@ -94,7 +136,7 @@ private void OnCustomizeElement(GridCustomizeElementEventArgs e) if (e.ElementType == GridElementType.GroupCell) { var elementBaseName = (string)e.Grid.GetRowValue(e.VisibleIndex, nameof(ParameterBaseRowViewModel.ElementBaseName)); - var isPublishableParameterInGroup = this.ViewModel.Rows.Items.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName); + var isPublishableParameterInGroup = this.sortedCollection.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName); if (isPublishableParameterInGroup) {