Skip to content

Commit 48f8e9b

Browse files
Tsvetomir-HrTsvetomir-Hr
authored andcommitted
chore: update example and apply suggested changes
1 parent 2f8d2a3 commit 48f8e9b

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

knowledge-base/grid-custom-filter-menu.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: How to Refresh Filter Menu Context After Programmatic Changes
2+
title: How to Refresh Filter Menu After Programmatic Changes
33
description: Learn how to refresh filter menu context after programmatic changes with a custom component
44
type: how-to
5-
page_title: How to Refresh Filter Menu Context After Programmatic Changes
5+
page_title: How to Refresh Filter Menu After Programmatic Changes
66
slug: grid-kb-custom-filter-menu
7-
tags: grid, blazor, custom, filter, filtermenu
7+
tags: blazor, grid, filter, filtermenu
88
res_type: kb
99
ticketid: 1669381
1010
---
@@ -21,20 +21,21 @@ ticketid: 1669381
2121

2222
## Description
2323

24-
When using the TelerikGrid in Blazor applications, it's common to implement custom `FilterMenu` for enhanced filtering capabilities. However, integrating an [AutoComplete]({%slug autocomplete-overview%}) component with `StringOperators` within a [`FilterMenuTemplate`]({%slug grid-templates-filter%}#filter-menu-template) for dynamic filtering based on user input does not work as expected. The AutoComplete component does not consider the selection from the dropdown list of `StringOperators` within the `FilterMenuTemplate`.
24+
When using the TelerikGrid in Blazor applications, it's common to implement a custom `FilterMenu` for enhanced filtering capabilities. However, integrating a Telerik UI for Blazor component that is responsible for the dynamic Grid filtering based on user input does not work as expected. For example, the [AutoComplete]({%slug autocomplete-overview%}) component does not consider the selection from the dropdown list of `StringOperators` within the [`FilterMenuTemplate`]({%slug grid-templates-filter%}#filter-menu-template).
2525

2626
This knowledge base article also answers the following questions:
2727
- How to integrate AutoComplete with `StringOperators` in a TelerikGrid `FilterMenuTemplate`?
28-
- How to refresh a custom `FilterMenuTemplate` in TelerikGrid?
29-
- How to refresh a `FilterMenuTemplate` context after programmatic changes?
28+
- How to refresh the contents of `FilterMenuTemplate` in a TelerikGrid?
29+
- How to refresh a `FilterMenuTemplate` after programmatic changes?
3030

3131
## Solution
3232

33-
To achieve the desired behavior, encapsulate the content of the `FilterMenuTemplate` in a custom component and refresh this component upon selection change in the dropdown list. Below is an example demonstrating this approach:
33+
To achieve the desired behavior, encapsulate the content of the `FilterMenuTemplate` in a separate Razor component and refresh this component upon selection change in the dropdown list. Below is an example demonstrating this approach:
3434

3535
<div class="skip-repl"></div>
3636
````Home.razor
3737
@using Telerik.DataSource
38+
3839
<TelerikGrid Data="@Countries"
3940
FilterMode="GridFilterMode.FilterMenu"
4041
PageSize="25">
@@ -62,19 +63,19 @@ To achieve the desired behavior, encapsulate the content of the `FilterMenuTempl
6263
6364
private async Task FilterAsync(FilterMenuTemplateContext filterContext)
6465
{
65-
FilterHandler(filterContext.FilterDescriptor);
66+
AddFilterDescriptor(filterContext.FilterDescriptor);
6667
await filterContext.FilterAsync();
6768
}
6869
6970
private async Task ClearFilterAsync(FilterMenuTemplateContext filterContext)
7071
{
7172
SelectedCountry = string.Empty;
7273
73-
FilterHandler(filterContext.FilterDescriptor);
74+
AddFilterDescriptor(filterContext.FilterDescriptor);
7475
filterContext.FilterDescriptor.FilterDescriptors.Clear();
7576
await filterContext.ClearFilterAsync();
7677
}
77-
private void FilterHandler(CompositeFilterDescriptor filterDescriptor)
78+
private void AddFilterDescriptor(CompositeFilterDescriptor filterDescriptor)
7879
{
7980
var model = string.Empty;
8081
object? value = null;
@@ -151,33 +152,40 @@ To achieve the desired behavior, encapsulate the content of the `FilterMenuTempl
151152
@using Microsoft.AspNetCore.Components
152153
@using static Home
153154
154-
Current filter operator: @FilterOperator
155-
155+
<label for="filterOperator"><b>Select Filter Operator for the AutoComplete:</b></label>
156156
<TelerikDropDownList Value="@FilterOperator"
157157
ValueChanged="@( (StringFilterOperator newValue) => OnFilterOperatorChanged(newValue) )"
158+
Id="filterOperator"
158159
Data="@FilterOperators"
159-
Width="160px">
160+
Width="200px">
161+
<DropDownListSettings>
162+
<DropDownListPopupSettings Height="auto"></DropDownListPopupSettings>
163+
</DropDownListSettings>
160164
</TelerikDropDownList>
161165
166+
<label for="autocomplete"><b>Filter the Grid by Country:</b></label>
162167
<TelerikAutoComplete ScrollMode="@DropDownScrollMode.Virtual"
163168
Value="@SelectedCountry"
164169
ValueChanged="@( (string selectedCountry) => HandleSelectedCountryChange(selectedCountry) )"
165170
TItem="Country"
166171
Data="@Countries"
167172
ValueField="CountryName"
168-
Width="300px"
173+
Width="200px"
169174
PageSize="20"
170175
Filterable="true"
171176
ItemHeight="35"
172177
FilterOperator="@FilterOperator">
178+
<AutoCompleteSettings>
179+
<AutoCompletePopupSettings Height="auto" MaxHeight="200px" MinHeight="75px" />
180+
</AutoCompleteSettings>
173181
</TelerikAutoComplete>
174182
175183
@code {
176184
[Parameter] public EventCallback<StringFilterOperator> FilterOperatorChanged { get; set; }
177185
[Parameter] public EventCallback<string> SelectedCountryChanged { get; set; }
178186
[Parameter] public StringFilterOperator FilterOperator { get; set; }
179-
[Parameter] public string SelectedCountry { get; set; } = null!;
180-
[Parameter] public IEnumerable<Country> Countries { get; set; } = null!;
187+
[Parameter] public string SelectedCountry { get; set; } = string.Empty;
188+
[Parameter] public IEnumerable<Country> Countries { get; set; } = Enumerable.Empty<Country>();
181189
[Parameter] public IEnumerable<StringFilterOperator> FilterOperators { get; set; } = null!;
182190
183191
private async Task OnFilterOperatorChanged(StringFilterOperator newValue)

0 commit comments

Comments
 (0)