@@ -19,6 +19,9 @@ namespace UI_DSM.Client.Components.NormalUser.Views
1919
2020 using DevExpress . Blazor ;
2121
22+ using Microsoft . AspNetCore . Components ;
23+ using Microsoft . JSInterop ;
24+
2225 using ReactiveUI ;
2326
2427 using UI_DSM . Client . ViewModels . Components . NormalUser . Views ;
@@ -35,11 +38,22 @@ public partial class RequirementBreakdownStructureView : GenericBaseView<IRequir
3538 /// </summary>
3639 private readonly List < IDisposable > disposables = new ( ) ;
3740
41+ /// <summary>
42+ /// Id of the element where the view should scroll to
43+ /// </summary>
44+ private Guid idToScrollTo ;
45+
3846 /// <summary>
3947 /// The <see cref="DxGrid" />
4048 /// </summary>
4149 protected DxGrid DxGrid { get ; set ; }
4250
51+ /// <summary>
52+ /// The <see cref="IJSRuntime" />
53+ /// </summary>
54+ [ Inject ]
55+ public IJSRuntime JsRuntime { get ; set ; }
56+
4357 /// <summary>
4458 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
4559 /// </summary>
@@ -70,11 +84,16 @@ public async Task<bool> CopyComponents(BaseView otherView)
7084 /// </summary>
7185 /// <param name="itemName">The name of the item to navigate to</param>
7286 /// <returns>A <see cref="Task" /></returns>
73- public override Task TryNavigateToItem ( string itemName )
87+ public override async Task TryNavigateToItem ( string itemName )
7488 {
7589 var item = this . ViewModel . Rows . FirstOrDefault ( x => string . Equals ( itemName , x . Id , StringComparison . InvariantCultureIgnoreCase ) ) ;
7690
77- return item != null ? this . DxGrid . SetFocusedDataItemAsync ( item ) : Task . CompletedTask ;
91+ if ( item != null )
92+ {
93+ await this . DxGrid . SetFocusedDataItemAsync ( item ) ;
94+ this . idToScrollTo = item . ThingId ;
95+ await this . HasChanged ( ) ;
96+ }
7897 }
7998
8099 /// <summary>
@@ -86,7 +105,7 @@ public override Task TryNavigateToItem(string itemName)
86105 /// <param name="reviewTaskId">The <see cref="ReviewTask" /> id</param>
87106 /// <param name="prefilters">A collection of prefilters</param>
88107 /// <param name="additionnalColumnsVisibleAtStart">A collection of columns name that can be visible by default at start</param>
89- /// <param name="participant">The current <see cref="Participant"/></param>
108+ /// <param name="participant">The current <see cref="Participant" /></param>
90109 /// <returns>A <see cref="Task" /></returns>
91110 public override async Task InitializeViewModel ( IEnumerable < Thing > things , Guid projectId , Guid reviewId , Guid reviewTaskId , List < string > prefilters , List < string > additionnalColumnsVisibleAtStart , Participant participant )
92111 {
@@ -116,6 +135,35 @@ protected void OnClick()
116135 this . DxGrid . ShowColumnChooser ( "#column-chooser" ) ;
117136 }
118137
138+ /// <summary>
139+ /// Method invoked after each time the component has been rendered. Note that the component does
140+ /// not automatically re-render after the completion of any returned <see cref="T:System.Threading.Tasks.Task" />, because
141+ /// that would cause an infinite render loop.
142+ /// </summary>
143+ /// <param name="firstRender">
144+ /// Set to <c>true</c> if this is the first time
145+ /// <see cref="M:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRender(System.Boolean)" /> has been invoked
146+ /// on this component instance; otherwise <c>false</c>.
147+ /// </param>
148+ /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing any asynchronous operation.</returns>
149+ /// <remarks>
150+ /// The <see cref="M:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRender(System.Boolean)" /> and
151+ /// <see cref="M:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync(System.Boolean)" /> lifecycle methods
152+ /// are useful for performing interop, or interacting with values received from <c>@ref</c>.
153+ /// Use the <paramref name="firstRender" /> parameter to ensure that initialization work is only performed
154+ /// once.
155+ /// </remarks>
156+ protected override async Task OnAfterRenderAsync ( bool firstRender )
157+ {
158+ await base . OnAfterRenderAsync ( firstRender ) ;
159+
160+ if ( this . idToScrollTo != Guid . Empty )
161+ {
162+ await this . JsRuntime . InvokeVoidAsync ( "scrollToElement" , $ "row_{ this . idToScrollTo } ", "center" , "center" ) ;
163+ this . idToScrollTo = Guid . Empty ;
164+ }
165+ }
166+
119167 /// <summary>
120168 /// Apply the filtering on rows
121169 /// </summary>
0 commit comments