@@ -12,6 +12,10 @@ public partial class Grid<TItem> : BlazorBootstrapComponentBase
1212
1313 private List < GridColumn < TItem > > columns = new ( ) ;
1414
15+ private GridDetailView < TItem > ? detailView ;
16+
17+ public GridEmptyDataTemplate < TItem > ? emptyDataTemplate ;
18+
1519 /// <summary>
1620 /// Current grid state (filters, paging, sorting).
1721 /// </summary>
@@ -21,18 +25,14 @@ public partial class Grid<TItem> : BlazorBootstrapComponentBase
2125
2226 private RenderFragment ? headerSelectionTemplate ;
2327
24- private GridDetailView < TItem > ? detailView ;
25-
26- public GridEmptyDataTemplate < TItem > ? emptyDataTemplate ;
27-
28- public GridLoadingTemplate < TItem > ? loadingTemplate ;
29-
3028 private bool isFirstRenderComplete = false ;
3129
3230 private List < TItem > ? items = null ;
3331
3432 private object ? lastAssignedDataOrDataProvider ;
3533
34+ public GridLoadingTemplate < TItem > ? loadingTemplate ;
35+
3636 private int pageSize ;
3737
3838 private bool requestInProgress = false ;
@@ -69,7 +69,8 @@ protected override void OnInitialized()
6969
7070 protected override Task OnParametersSetAsync ( )
7171 {
72- if ( ( Data is null && DataProvider is null ) || ( Data is not null && DataProvider is not null ) ) throw new ArgumentException ( $ "Grid requires either { nameof ( Data ) } or { nameof ( DataProvider ) } , but not both or neither.") ;
72+ if ( ( Data is null && DataProvider is null ) || ( Data is not null && DataProvider is not null ) )
73+ throw new ArgumentException ( $ "Grid requires either { nameof ( Data ) } or { nameof ( DataProvider ) } , but not both or neither.") ;
7374
7475 if ( AllowPaging && PageSize < 0 )
7576 throw new ArgumentException ( $ "{ nameof ( PageSize ) } must be greater than zero.") ;
@@ -123,6 +124,10 @@ protected override Task OnParametersSetAsync()
123124 /// </summary>
124125 public async ValueTask ResetPageNumber ( ) => await ResetPageNumberAsync ( true ) ;
125126
127+ public Task SelectAllItemsAsync ( ) => SelectAllItemsInternalAsync ( true ) ;
128+
129+ public Task UnSelectAllItemsAsync ( ) => SelectAllItemsInternalAsync ( false ) ;
130+
126131 internal void AddColumn ( GridColumn < TItem > column ) => columns . Add ( column ) ;
127132
128133 internal async Task FilterChangedAsync ( )
@@ -158,13 +163,13 @@ internal async Task RefreshDataAsync(bool firstRender = false, CancellationToken
158163 await LoadGridSettingsAsync ( ) ;
159164
160165 var request = new GridDataProviderRequest < TItem >
161- {
162- PageNumber = AllowPaging ? gridCurrentState . PageIndex : 0 ,
163- PageSize = AllowPaging ? pageSize : 0 ,
164- Sorting = AllowSorting ? gridCurrentState . Sorting ?? GetDefaultSorting ( ) ! : null ! ,
165- Filters = AllowFiltering ? GetFilters ( ) ! : null ! ,
166- CancellationToken = cancellationToken
167- } ;
166+ {
167+ PageNumber = AllowPaging ? gridCurrentState . PageIndex : 0 ,
168+ PageSize = AllowPaging ? pageSize : 0 ,
169+ Sorting = AllowSorting ? gridCurrentState . Sorting ?? GetDefaultSorting ( ) ! : null ! ,
170+ Filters = AllowFiltering ? GetFilters ( ) ! : null ! ,
171+ CancellationToken = cancellationToken
172+ } ;
168173
169174 GridDataProviderResult < TItem > result = default ! ;
170175
@@ -205,6 +210,12 @@ internal async ValueTask ResetPageNumberAsync(bool refreshGrid = false)
205210 await RefreshDataAsync ( false ) ;
206211 }
207212
213+ internal void SetGridDetailView ( GridDetailView < TItem > detailView ) => this . detailView = detailView ;
214+
215+ internal void SetGridEmptyDataTemplate ( GridEmptyDataTemplate < TItem > emptyDataTemplate ) => this . emptyDataTemplate = emptyDataTemplate ;
216+
217+ internal void SetGridLoadingTemplate ( GridLoadingTemplate < TItem > loadingTemplate ) => this . loadingTemplate = loadingTemplate ;
218+
208219 internal async Task SortingChangedAsync ( GridColumn < TItem > column )
209220 {
210221 if ( columns == null || ! columns . Any ( ) )
@@ -380,13 +391,8 @@ private async Task LoadGridSettingsAsync()
380391
381392 private async Task OnHeaderCheckboxChanged ( ChangeEventArgs args )
382393 {
383- allItemsSelected = bool . TryParse ( args ? . Value ? . ToString ( ) , out var checkboxState ) && checkboxState ;
384- selectedItems = allItemsSelected ? new HashSet < TItem > ( items ! ) : new HashSet < TItem > ( ) ;
385- SelectedItemsCount = selectedItems . Count ;
386- await CheckOrUnCheckAll ( ) ;
387-
388- if ( SelectedItemsChanged . HasDelegate )
389- await SelectedItemsChanged . InvokeAsync ( selectedItems ) ;
394+ var headerCheckboxState = bool . TryParse ( args ? . Value ? . ToString ( ) , out var checkboxState ) && checkboxState ;
395+ await SelectAllItemsInternalAsync ( headerCheckboxState ) ;
390396 }
391397
392398 private async Task OnPageChangedAsync ( int newPageNumber )
@@ -495,13 +501,27 @@ private Task SaveGridSettingsAsync()
495501 return GridSettingsChanged . InvokeAsync ( settings ) ;
496502 }
497503
498- private async Task SetCheckboxStateAsync ( string id , CheckboxState checkboxState ) => await JSRuntime . InvokeVoidAsync ( "window.blazorBootstrap.grid.setSelectAllCheckboxState" , id , ( int ) checkboxState ) ;
504+ private async Task SelectAllItemsInternalAsync ( bool selectAll )
505+ {
506+ if ( SelectionMode != GridSelectionMode . Multiple )
507+ return ;
499508
500- internal void SetGridDetailView ( GridDetailView < TItem > detailView ) => this . detailView = detailView ;
509+ allItemsSelected = selectAll ;
510+ selectedItems = allItemsSelected ? new HashSet < TItem > ( items ! ) : new HashSet < TItem > ( ) ;
511+ SelectedItemsCount = allItemsSelected ? selectedItems . Count : 0 ;
501512
502- internal void SetGridEmptyDataTemplate ( GridEmptyDataTemplate < TItem > emptyDataTemplate ) => this . emptyDataTemplate = emptyDataTemplate ;
513+ if ( allItemsSelected )
514+ await SetCheckboxStateAsync ( headerCheckboxId , CheckboxState . Checked ) ;
515+ else
516+ await SetCheckboxStateAsync ( headerCheckboxId , CheckboxState . Unchecked ) ;
503517
504- internal void SetGridLoadingTemplate ( GridLoadingTemplate < TItem > loadingTemplate ) => this . loadingTemplate = loadingTemplate ;
518+ await CheckOrUnCheckAll ( ) ;
519+
520+ if ( SelectedItemsChanged . HasDelegate )
521+ await SelectedItemsChanged . InvokeAsync ( selectedItems ) ;
522+ }
523+
524+ private async Task SetCheckboxStateAsync ( string id , CheckboxState checkboxState ) => await JSRuntime . InvokeVoidAsync ( "window.blazorBootstrap.grid.setSelectAllCheckboxState" , id , ( int ) checkboxState ) ;
505525
506526 /// <summary>
507527 /// Set filters.
@@ -534,9 +554,11 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
534554 #region Properties, Indexers
535555
536556 protected override string ? ClassNames =>
537- BuildClassNames ( Class ,
557+ BuildClassNames (
558+ Class ,
538559 ( "bb-table" , true ) ,
539- ( BootstrapClass . TableSticky , FixedHeader ) ) ;
560+ ( BootstrapClass . TableSticky , FixedHeader )
561+ ) ;
540562
541563 /// <summary>
542564 /// Gets or sets the grid delete.
@@ -705,8 +727,10 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
705727 public string ? GridContainerClass { get ; set ; }
706728
707729 private string ? GridContainerClassNames =>
708- BuildClassNames ( GridContainerClass ,
709- ( BootstrapClass . TableResponsive , Responsive ) ) ;
730+ BuildClassNames (
731+ GridContainerClass ,
732+ ( BootstrapClass . TableResponsive , Responsive )
733+ ) ;
710734
711735 /// <summary>
712736 /// Gets or sets the grid container css style.
@@ -715,8 +739,10 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
715739 public string ? GridContainerStyle { get ; set ; }
716740
717741 private string ? GridContainerStyleNames =>
718- BuildStyleNames ( GridContainerStyle ,
719- ( $ "height:{ Height . ToString ( CultureInfo . InvariantCulture ) } { Unit . ToCssString ( ) } ", FixedHeader ) ) ;
742+ BuildStyleNames (
743+ GridContainerStyle ,
744+ ( $ "height:{ Height . ToString ( CultureInfo . InvariantCulture ) } { Unit . ToCssString ( ) } ", FixedHeader )
745+ ) ;
720746
721747 /// <summary>
722748 /// This event is fired when the grid state is changed.
0 commit comments