Skip to content

Commit dea6ecc

Browse files
chore(grid): fix custom filter menu example to properly uncheck checkboxes on filter clear
1 parent e6f713b commit dea6ecc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

components/grid/templates/filter.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ This custom filter menu lets you choose more than one option to match against th
212212
@foreach (var size in Sizes)
213213
{
214214
<div>
215-
<TelerikCheckBox Value="@(CheckedSizes.Contains(size))"
216-
TValue="bool"
217-
ValueChanged="@((value) => UpdateCheckedSizes(value, size))"
218-
Id="@($"size_{size}")">
215+
<TelerikCheckBox Value="@(IsCheckboxInCurrentFilter(context.FilterDescriptor, size))"
216+
TValue="bool"
217+
ValueChanged="@((value) => UpdateCheckedSizes(value, size))"
218+
Id="@($"size_{size}")">
219219
</TelerikCheckBox>
220220
<label for="@($"size_{size}")">
221221
@size
@@ -233,6 +233,12 @@ This custom filter menu lets you choose more than one option to match against th
233233
FilterMenuTemplateContext theFilterContext { get; set; }
234234
public List<string> CheckedSizes { get; set; } = new List<string>();
235235
236+
public bool IsCheckboxInCurrentFilter(CompositeFilterDescriptor filterDescriptor, string size)
237+
{
238+
// get all current filter descriptors and evaluate whether to select the current checkbox
239+
return filterDescriptor.FilterDescriptors.Select(f => (f as FilterDescriptor).Value?.ToString()).ToList().Contains(size);
240+
}
241+
236242
public void UpdateCheckedSizes(bool value, string itemValue)
237243
{
238244
// update the list of items we want to filter by

0 commit comments

Comments
 (0)