From b49aa4e36c4979e229604b1e57700ff45419d7c9 Mon Sep 17 00:00:00 2001 From: Mark Kamberger Date: Mon, 25 Nov 2024 21:13:11 -0500 Subject: [PATCH 1/3] Created parameter "SetSelected" to allow setting of selected items while using the grid in an edit context --- blazorbootstrap/Components/Grid/Grid.razor.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/blazorbootstrap/Components/Grid/Grid.razor.cs b/blazorbootstrap/Components/Grid/Grid.razor.cs index 2a90de27b..76cbb3723 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor.cs +++ b/blazorbootstrap/Components/Grid/Grid.razor.cs @@ -53,7 +53,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { await RefreshDataAsync(firstRender); isFirstRenderComplete = true; - } + } await base.OnAfterRenderAsync(firstRender); } @@ -383,6 +383,7 @@ private async Task OnHeaderCheckboxChanged(ChangeEventArgs args) allItemsSelected = bool.TryParse(args?.Value?.ToString(), out var checkboxState) && checkboxState; selectedItems = allItemsSelected ? new HashSet(items!) : new HashSet(); SelectedItemsCount = selectedItems.Count; + SetSelected = selectedItems; await CheckOrUnCheckAll(); if (SelectedItemsChanged.HasDelegate) @@ -456,8 +457,8 @@ private void PrepareCheckboxIds() private async Task RefreshSelectionAsync() { selectedItems = (items?.Count ?? 0) == 0 - ? new HashSet() - : selectedItems?.Intersect(items!).ToHashSet() ?? new HashSet(); + ? new HashSet() + : selectedItems?.Intersect(items!).ToHashSet() ?? new HashSet(); SelectedItemsCount = selectedItems.Count; allItemsSelected = SelectedItemsCount > 0 && items!.Count == SelectedItemsCount; @@ -584,6 +585,19 @@ private void SetFilters(IEnumerable filterItems) [Parameter] public bool AllowRowClick { get; set; } + /// + /// Gets or sets the grid set selection. + /// + /// + /// Default value is false. + /// + [Parameter] + public HashSet SetSelected + { + get => selectedItems; + set => selectedItems = value; + } + /// /// Gets or sets the grid selection. /// From 51981141610a9717ba61e2aabf62a7c9089538c5 Mon Sep 17 00:00:00 2001 From: Mark Kamberger Date: Mon, 25 Nov 2024 21:16:00 -0500 Subject: [PATCH 2/3] Remove space --- blazorbootstrap/Components/Grid/Grid.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blazorbootstrap/Components/Grid/Grid.razor.cs b/blazorbootstrap/Components/Grid/Grid.razor.cs index 76cbb3723..81a410077 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor.cs +++ b/blazorbootstrap/Components/Grid/Grid.razor.cs @@ -53,7 +53,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { await RefreshDataAsync(firstRender); isFirstRenderComplete = true; - } + } await base.OnAfterRenderAsync(firstRender); } From 72c5f64948cda3023f9996fd4252a61b7cfdb353 Mon Sep 17 00:00:00 2001 From: Mark Kamberger Date: Tue, 26 Nov 2024 12:44:53 -0500 Subject: [PATCH 3/3] AllIn --- blazorbootstrap/Components/Grid/Grid.razor.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/blazorbootstrap/Components/Grid/Grid.razor.cs b/blazorbootstrap/Components/Grid/Grid.razor.cs index 81a410077..50fd95a4f 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor.cs +++ b/blazorbootstrap/Components/Grid/Grid.razor.cs @@ -186,10 +186,8 @@ internal async Task RefreshDataAsync(bool firstRender = false, CancellationToken if (AllowSelection) { - PrepareCheckboxIds(); - - if (!firstRender) - await RefreshSelectionAsync(); + PrepareCheckboxIds(); + await RefreshSelectionAsync(); } requestInProgress = false;