Skip to content

Commit 3f4f83d

Browse files
committed
PivotDataGrid filter icon popup exception after adding more fields
1 parent 3dea547 commit 3f4f83d

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Radzen.Blazor/RadzenPivotDataGrid.razor

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
var isFilterable = AllowFiltering && row?.Filterable == true;
9090
var sortOrder = row?.GetSortOrder();
9191
var hasActiveFilter = row?.HasActiveFilter() == true;
92+
var filterIconRefKey = $"row{row.GetFilterProperty()}";
9293
<tr class="rz-pivot-header-row">
9394
<th class="rz-pivot-row-header @(isSortable ? "rz-sortable-column" : "")" style="width:100%;margin-top:5px;">
9495
<div class="rz-pivot-header-content-wrapper">
@@ -117,8 +118,8 @@
117118
</div>
118119
@if (isFilterable)
119120
{
120-
<i @ref="FilterIconRef[row]" @onclick:stopPropagation="true"
121-
@onmousedown="@(() => ToggleFilter(row))"
121+
<i @ref=FilterIconRef[filterIconRefKey] @onclick:stopPropagation="true"
122+
@onmousedown="@(() => ToggleFilter(row, filterIconRefKey))"
122123
class="@GetFilterIconCss(row)"
123124
title="Filter">
124125
@FilterIcon
@@ -141,7 +142,7 @@
141142
var isFilterable = AllowFiltering && column?.Filterable == true;
142143
var sortOrder = column?.GetSortOrder();
143144
var hasActiveFilter = column?.HasActiveFilter() == true;
144-
145+
var filterIconRefKey = $"col{column.GetFilterProperty()}";
145146
<tr class="rz-pivot-header-row">
146147
<th class="rz-pivot-column-header @(isSortable ? "rz-sortable-column" : "")" style="width:100%;margin-top:5px;">
147148
<div class="rz-pivot-header-content-wrapper">
@@ -170,8 +171,8 @@
170171
</div>
171172
@if (isFilterable)
172173
{
173-
<i @ref="FilterIconRef[column]" @onclick:stopPropagation="true"
174-
@onmousedown="@(() => ToggleFilter(column))"
174+
<i @ref=FilterIconRef[filterIconRefKey] @onclick:stopPropagation="true"
175+
@onmousedown="@(() => ToggleFilter(column, filterIconRefKey))"
175176
class="@GetFilterIconCss(column)"
176177
title="Filter">
177178
@FilterIcon
@@ -194,7 +195,7 @@
194195
var isFilterable = AllowFiltering && column?.Filterable == true;
195196
var sortOrder = column?.GetSortOrder();
196197
var hasActiveFilter = column?.HasActiveFilter() == true;
197-
198+
var filterIconRefKey = $"agg{column.GetFilterProperty()}";
198199
<tr class="rz-pivot-header-row">
199200
<th class="rz-pivot-column-header @(isSortable ? "rz-sortable-column" : "")" style="width:100%;margin-top:5px;">
200201
<div class="rz-pivot-header-content-wrapper">
@@ -223,8 +224,8 @@
223224
</div>
224225
@if (isFilterable)
225226
{
226-
<i @ref="FilterIconRef[column]" @onclick:stopPropagation="true"
227-
@onmousedown="@(() => ToggleFilter(column))"
227+
<i @ref=FilterIconRef[filterIconRefKey] @onclick:stopPropagation="true"
228+
@onmousedown="@(() => ToggleFilter(column, filterIconRefKey))"
228229
class="@GetFilterIconCss(column)"
229230
title="Filter">
230231
@FilterIcon
@@ -427,16 +428,18 @@
427428
<!-- Filter Popup -->
428429
@if (AllowFiltering && currentFilterField != null)
429430
{
431+
var prefix = currentFilterField is RadzenPivotColumn<TItem> ? "col" : currentFilterField is RadzenPivotRow<TItem> ? "row" : "agg";
432+
var filterIconRefKey = $"{prefix}{currentFilterField.GetFilterProperty()}";
430433
<Popup @ref="filterPopup" id="@($"pivot-filter-{currentFilterField.Property}")" class="rz-overlaypanel"
431-
style="display:none;min-width:250px;" @onkeydown="OnFilterPopupKeyPressed">
434+
style="display:none;min-width:250px;" @onkeydown=@(args => OnFilterPopupKeyPressed(args, filterIconRefKey))>
432435
<div class="rz-overlaypanel-content">
433436
@if (currentFilterField.FilterTemplate != null)
434437
{
435438
@currentFilterField.FilterTemplate(currentFilterField)
436439
}
437440
else
438441
{
439-
<form id="@($"pivot-filter-{currentFilterField.Property}-form")" @onsubmit="@(args => ApplyFilter())" class="rz-grid-filter">
442+
<form id="@($"pivot-filter-{currentFilterField.Property}-form")" @onsubmit="@(args => ApplyFilter(filterIconRefKey))" class="rz-grid-filter">
440443
<span class="rz-grid-filter-label">@FilterText</span>
441444
<RadzenDropDown InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", FilterOperatorAriaLabel + GetFilterOperatorText(currentFilterField.GetSecondFilterOperator()) }})"
442445
@onclick:preventDefault="true" Data="@(GetFilterOperators(currentFilterField).Select(t => new { Value = GetFilterOperatorText(t), Key = t }))" TextProperty="Value" ValueProperty="Key" TValue="FilterOperator?" Value="@currentFilterField.GetFilterOperator()" Change="@(args => SetFilterOperator(currentFilterField, (FilterOperator)args))" />
@@ -505,7 +508,7 @@
505508
</form>
506509
<div class="rz-grid-filter-buttons">
507510
<RadzenButton ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Text="@ApplyText" class="rz-button-sm" />
508-
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="@ClearText" Click="@ClearFilter" class="rz-button-sm" />
511+
<RadzenButton ButtonStyle="ButtonStyle.Light" Text="@ClearText" Click="@(args => ClearFilter(filterIconRefKey))" class="rz-button-sm" />
509512
</div>
510513
}
511514
</div>

Radzen.Blazor/RadzenPivotDataGrid.razor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,12 +1630,12 @@ private string GetFilterIconCss(RadzenPivotField<TItem> field)
16301630
/// <summary>
16311631
/// Gets or sets the current filter icon reference.
16321632
/// </summary>
1633-
private Dictionary<RadzenPivotField<TItem>, ElementReference> FilterIconRef = new();
1633+
private Dictionary<string, ElementReference> FilterIconRef = new();
16341634

16351635
/// <summary>
16361636
/// Toggles the filter popup for a field.
16371637
/// </summary>
1638-
private async Task ToggleFilter(RadzenPivotField<TItem> field)
1638+
private async Task ToggleFilter(RadzenPivotField<TItem> field, string filterIconRefKey)
16391639
{
16401640
if (field == null || !AllowFiltering || !field.Filterable)
16411641
return;
@@ -1647,7 +1647,7 @@ private async Task ToggleFilter(RadzenPivotField<TItem> field)
16471647

16481648
if (filterPopup != null)
16491649
{
1650-
await filterPopup.ToggleAsync(FilterIconRef[field]);
1650+
await filterPopup.ToggleAsync(FilterIconRef[filterIconRefKey]);
16511651
}
16521652
}
16531653

@@ -1806,7 +1806,7 @@ private void SetFilterValue(RadzenPivotField<TItem> field, object value, bool is
18061806
/// <summary>
18071807
/// Applies the current filter.
18081808
/// </summary>
1809-
private async Task ApplyFilter()
1809+
private async Task ApplyFilter(string filterIconRefKey)
18101810
{
18111811
if (currentFilterField != null)
18121812
{
@@ -1815,15 +1815,15 @@ private async Task ApplyFilter()
18151815

18161816
if (filterPopup != null)
18171817
{
1818-
await filterPopup.CloseAsync(FilterIconRef[currentFilterField]);
1818+
await filterPopup.CloseAsync(FilterIconRef[filterIconRefKey]);
18191819
}
18201820
}
18211821
}
18221822

18231823
/// <summary>
18241824
/// Clears the current filter.
18251825
/// </summary>
1826-
private async Task ClearFilter()
1826+
private async Task ClearFilter(string filterIconRefKey)
18271827
{
18281828
if (currentFilterField != null)
18291829
{
@@ -1835,22 +1835,22 @@ private async Task ClearFilter()
18351835

18361836
if (filterPopup != null)
18371837
{
1838-
await filterPopup.CloseAsync(FilterIconRef[currentFilterField]);
1838+
await filterPopup.CloseAsync(FilterIconRef[filterIconRefKey]);
18391839
}
18401840
}
18411841
}
18421842

18431843
/// <summary>
18441844
/// Handles filter popup key pressed events.
18451845
/// </summary>
1846-
private async Task OnFilterPopupKeyPressed(KeyboardEventArgs args)
1846+
private async Task OnFilterPopupKeyPressed(KeyboardEventArgs args, string filterIconRefKey)
18471847
{
18481848
var key = args.Code ?? args.Key;
18491849
if (key == "Escape")
18501850
{
18511851
if (filterPopup != null && currentFilterField != null)
18521852
{
1853-
await filterPopup.CloseAsync(FilterIconRef[currentFilterField]);
1853+
await filterPopup.CloseAsync(FilterIconRef[filterIconRefKey]);
18541854
}
18551855
}
18561856
}

0 commit comments

Comments
 (0)