@@ -22,6 +22,7 @@ public abstract class DataComponentBase<TItem> : ComponentBase, IDisposable
2222 private IEnumerable < TItem > ? _data ;
2323 private bool _isLoading ;
2424 private DataSort ? _currentSort ;
25+ private QueryGroup ? _initialQuery ;
2526
2627 /// <summary>
2728 /// Gets or sets the JavaScript runtime for interop calls.
@@ -157,12 +158,18 @@ public abstract class DataComponentBase<TItem> : ComponentBase, IDisposable
157158 [ Parameter ]
158159 public QueryGroup ? Query { get ; set ; }
159160
161+ /// <summary>
162+ /// Event triggered when the data grid is initialized.
163+ /// </summary>
164+ [ Parameter ]
165+ public EventCallback < DataGrid < TItem > > Initialized { get ; set ; }
166+
160167 /// <summary>
161168 /// Gets the root query group for filtering and searching.
162169 /// This is the primary filter container that holds all active filters and query groups.
163170 /// It's automatically managed by the component's filter operations but can be accessed for advanced scenarios.
164171 /// </summary>
165- public QueryGroup RootQuery { get ; private set ; } = new ( ) ;
172+ public QueryGroup RootQuery { get ; } = new ( ) ;
166173
167174 /// <summary>
168175 /// Gets or sets a value indicating whether the component is currently loading data.
@@ -295,18 +302,22 @@ public async Task ClearFilters()
295302 /// This method allows programmatic application of filters without user interaction with the filter UI.
296303 /// </summary>
297304 /// <param name="rules">The collection of filter rules to apply. Each rule defines a specific filter condition.</param>
298- /// <param name="replace">When true, existing filters are cleared before applying new rules.
299- /// When false, new rules are added to existing filters.</param>
305+ /// <param name="replace">
306+ /// When true, existing filters are cleared before applying new rules.
307+ /// When false, new rules are added to existing filters.
308+ /// </param>
309+ /// <param name="refresh">Whether to refresh the data display after applying the filter.</param>
300310 /// <returns>A task representing the asynchronous filter application and data refresh operation.</returns>
301- public async Task ApplyFilters ( IEnumerable < QueryRule > rules , bool replace = false )
311+ public async Task ApplyFilters ( IEnumerable < QueryRule > rules , bool replace = false , bool refresh = true )
302312 {
303313 if ( replace )
304314 RootQuery . Filters . Clear ( ) ;
305315
306316 if ( rules != null )
307317 RootQuery . Filters . AddRange ( rules ) ;
308318
309- await RefreshAsync ( true ) ;
319+ if ( refresh )
320+ await RefreshAsync ( true ) ;
310321 }
311322
312323 /// <summary>
@@ -315,8 +326,9 @@ public async Task ApplyFilters(IEnumerable<QueryRule> rules, bool replace = fals
315326 /// This allows for easy updates to existing filters without duplicating filter conditions.
316327 /// </summary>
317328 /// <param name="rule">The filter rule to apply. If null, no action is taken.</param>
329+ /// <param name="refresh">Whether to refresh the data display after applying the filter.</param>
318330 /// <returns>A task representing the asynchronous filter application and data refresh operation.</returns>
319- public async Task ApplyFilter ( QueryRule rule )
331+ public async Task ApplyFilter ( QueryRule ? rule , bool refresh = true )
320332 {
321333 if ( rule == null )
322334 return ;
@@ -325,7 +337,9 @@ public async Task ApplyFilter(QueryRule rule)
325337 RootQuery . Filters . RemoveAll ( f => f . Id == rule . Id ) ;
326338
327339 RootQuery . Filters . Add ( rule ) ;
328- await RefreshAsync ( true ) ;
340+
341+ if ( refresh )
342+ await RefreshAsync ( true ) ;
329343 }
330344
331345 /// <summary>
@@ -400,6 +414,12 @@ protected override void OnInitialized()
400414 /// <inheritdoc />
401415 protected override async Task OnParametersSetAsync ( )
402416 {
417+ if ( _initialQuery != Query )
418+ {
419+ await ApplyFilter ( Query , false ) ;
420+ _initialQuery = Query ;
421+ }
422+
403423 if ( DataProvider != null )
404424 {
405425 if ( Data != null || DataLoader != null )
@@ -439,6 +459,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
439459 if ( ! firstRender )
440460 return ;
441461
462+ // notify initialized
463+ await Initialized . InvokeAsync ( ( DataGrid < TItem > ) this ) ;
464+
442465 // re-render due to columns being added
443466 await RefreshAsync ( ) ;
444467 }
@@ -626,7 +649,7 @@ protected virtual IQueryable<TItem> SortData(IQueryable<TItem> queryable, DataRe
626649 if ( ! Sortable || request . Sorts == null || request . Sorts . Length == 0 )
627650 return queryable ;
628651
629- return queryable . Sort ( request . Sorts ) ;
652+ return queryable . Sort ( request . Sorts ) ;
630653 }
631654
632655 /// <summary>
0 commit comments