[PR #1794] [MERGED] Fix FilterString generation for the FilterOperator.In and FilterOperator.NotIn #2900

Open
opened 2026-01-29 18:20:58 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/radzenhq/radzen-blazor/pull/1794
Author: @k-Sacr
Created: 11/18/2024
Status: Merged
Merged: 11/18/2024
Merged by: @enchev

Base: masterHead: Fix-FilterString-generation-for-the-FilterOperator.In-and-FilterOperator.NotIn


📝 Commits (1)

  • 6dd1a36 Fix FilterString generation for the FilterOperator.In and FilterOperator.NotIn

📊 Changes

1 file changed (+27 additions, -13 deletions)

View changed files

📝 Radzen.Blazor/QueryableExtension.cs (+27 -13)

📄 Description

After the commit 0f7f717330 (diff-5e70b54e61695944357a6150dbcaf61f03f7c31d03f3e85fc1943de042d8f045R173), the filter in RadzenDataGrid broke.

An example for test can be found in the pull request: https://github.com/radzenhq/radzen-blazor/pull/1260

Current behavior:

https://github.com/user-attachments/assets/84cbb9d2-e418-42af-a748-814c4cb79144

The FilterString generates an incorrect string: "(Color).Intersect((Red)).Any()"

Fix:

https://github.com/user-attachments/assets/f8e62264-c386-43cd-87ea-e8e4f54e60f1

The FilterString generates the correct string: "(Color).Intersect(new ColorType[]{Red,AlmondGreen}).Any()"

Demo page:

@using System.Linq.Dynamic.Core
@using System.ComponentModel.DataAnnotations
@using Radzen.Blazor

@inject IJSRuntime JSRuntime

<RadzenDataGrid LoadData="LoadData" IsLoading=@isLoading Count="count" Data=@employees FilterMode="FilterMode.Simple"
				AllowFiltering="true" AllowPaging="true" AllowSorting="true" TItem="Employee" ColumnWidth="200px">
	<Columns>
		<RadzenDataGridColumn TItem="Employee" Property="ID" Title="ID" />
		<RadzenDataGridColumn TItem="Employee" Property="Gender" Title="Gender" />
		<RadzenDataGridColumn TItem="Employee" Property="Status" Title="Nullable Status" />
		<RadzenDataGridColumn TItem="Employee" Property="Color"
							  Title="Favorite Color (Display Attribute in Filter)"
							  Sortable="false" FilterOperator="FilterOperator.In" Type="typeof(IEnumerable<ColorType>)">
			<FilterTemplate>
				<RadzenDropDown TValue="IEnumerable<ColorType>" Value="context.GetFilterValue()"
								ValueChanged="v => context.SetFilterValueAsync(v)" Multiple="true" AllowClear="true"
								AllowSelectAll="false" Style="width:100%;"
								Data=_allColors TextProperty="Text" ValueProperty="Value" />
			</FilterTemplate>
			<Template Context="item">
				@(string.Join(", ", item.Color.ToList()))
			</Template>
		</RadzenDataGridColumn>
	</Columns>
</RadzenDataGrid>
<EventConsole @ref=@console />

@code {
	int count;
	IEnumerable<Employee> initialEmployees;
	IEnumerable<Employee> employees;
	bool isLoading = false;
	EventConsole console;

	public sealed record SelectListEnum<TEnum>(string Text, TEnum? Value);


	List<SelectListEnum<ColorType>> _allColors = Enum.GetValues(typeof(ColorType))
		.Cast<ColorType>()
		.Select(elem => new SelectListEnum<ColorType>
		(
			elem.GetDisplayDescription(),
			elem
		))
		.ToList();

	public class Employee
	{
		public int ID { get; set; }
		public GenderType Gender { get; set; }
		public StatusType? Status { get; set; }
		public IEnumerable<ColorType>? Color { get; set; }
	}

	public enum GenderType
	{
		Ms,
		Mr,
		Unknown,
	}

	public enum ColorType
	{
		Red,
		Green,
		Blue,
		[Display(Description = "Almond Green")]
		AlmondGreen,
		[Display(Description = "Amber Gray")]
		AmberGray,
		[Display(Description = "Apple Blue... ")]
		AppleBlueSeaGreen,
		[Display(Description = "Azure")]
		AzureBlue,

	}

	public enum StatusType
	{
		Inactive,
		Active,
	}

	protected override void OnInitialized()
	{
		initialEmployees = Enumerable.Range(0, 10).Select(i =>
			new Employee
				{
					ID = i,
					Gender = i < 3 ? GenderType.Mr : i < 6 ? GenderType.Ms : GenderType.Unknown,
					Status = i < 3 ? StatusType.Active : i < 6 ? StatusType.Inactive : null,
					Color = i < 3 ? [_allColors[0].Value, _allColors[2].Value]
						: i < 6 ? [_allColors[1].Value, _allColors[3].Value]
						: [_allColors[4].Value, _allColors[6].Value],
				});
	}

	void LoadData(LoadDataArgs args)
	{
		isLoading = true;
		console.Log($"LoadData. {DateTime.Now.ToLongTimeString()}");
		var query = initialEmployees.AsQueryable();

		if (!string.IsNullOrEmpty(args.Filter))
		{
			query = query.Where(args.Filter);
		}
		if (!string.IsNullOrEmpty(args.OrderBy))
		{
			query = query.OrderBy(args.OrderBy);
		}

		count = query.Count();

		employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
		isLoading = false;

	}
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/radzenhq/radzen-blazor/pull/1794 **Author:** [@k-Sacr](https://github.com/k-Sacr) **Created:** 11/18/2024 **Status:** ✅ Merged **Merged:** 11/18/2024 **Merged by:** [@enchev](https://github.com/enchev) **Base:** `master` ← **Head:** `Fix-FilterString-generation-for-the-FilterOperator.In-and-FilterOperator.NotIn` --- ### 📝 Commits (1) - [`6dd1a36`](https://github.com/radzenhq/radzen-blazor/commit/6dd1a362ccf18a5a6414a4ffac2bca6b7b32f621) Fix FilterString generation for the FilterOperator.In and FilterOperator.NotIn ### 📊 Changes **1 file changed** (+27 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `Radzen.Blazor/QueryableExtension.cs` (+27 -13) </details> ### 📄 Description After the commit https://github.com/radzenhq/radzen-blazor/commit/0f7f7173300544493f4edd56682a5c59c8761e23?diff=split#diff-5e70b54e61695944357a6150dbcaf61f03f7c31d03f3e85fc1943de042d8f045R173, the filter in RadzenDataGrid broke. An example for test can be found in the pull request: https://github.com/radzenhq/radzen-blazor/pull/1260 Current behavior: https://github.com/user-attachments/assets/84cbb9d2-e418-42af-a748-814c4cb79144 **The FilterString generates an incorrect string: `"(Color).Intersect((Red)).Any()"`** Fix: https://github.com/user-attachments/assets/f8e62264-c386-43cd-87ea-e8e4f54e60f1 **The FilterString generates the correct string: `"(Color).Intersect(new ColorType[]{Red,AlmondGreen}).Any()"`** Demo page: ``` @using System.Linq.Dynamic.Core @using System.ComponentModel.DataAnnotations @using Radzen.Blazor @inject IJSRuntime JSRuntime <RadzenDataGrid LoadData="LoadData" IsLoading=@isLoading Count="count" Data=@employees FilterMode="FilterMode.Simple" AllowFiltering="true" AllowPaging="true" AllowSorting="true" TItem="Employee" ColumnWidth="200px"> <Columns> <RadzenDataGridColumn TItem="Employee" Property="ID" Title="ID" /> <RadzenDataGridColumn TItem="Employee" Property="Gender" Title="Gender" /> <RadzenDataGridColumn TItem="Employee" Property="Status" Title="Nullable Status" /> <RadzenDataGridColumn TItem="Employee" Property="Color" Title="Favorite Color (Display Attribute in Filter)" Sortable="false" FilterOperator="FilterOperator.In" Type="typeof(IEnumerable<ColorType>)"> <FilterTemplate> <RadzenDropDown TValue="IEnumerable<ColorType>" Value="context.GetFilterValue()" ValueChanged="v => context.SetFilterValueAsync(v)" Multiple="true" AllowClear="true" AllowSelectAll="false" Style="width:100%;" Data=_allColors TextProperty="Text" ValueProperty="Value" /> </FilterTemplate> <Template Context="item"> @(string.Join(", ", item.Color.ToList())) </Template> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> <EventConsole @ref=@console /> @code { int count; IEnumerable<Employee> initialEmployees; IEnumerable<Employee> employees; bool isLoading = false; EventConsole console; public sealed record SelectListEnum<TEnum>(string Text, TEnum? Value); List<SelectListEnum<ColorType>> _allColors = Enum.GetValues(typeof(ColorType)) .Cast<ColorType>() .Select(elem => new SelectListEnum<ColorType> ( elem.GetDisplayDescription(), elem )) .ToList(); public class Employee { public int ID { get; set; } public GenderType Gender { get; set; } public StatusType? Status { get; set; } public IEnumerable<ColorType>? Color { get; set; } } public enum GenderType { Ms, Mr, Unknown, } public enum ColorType { Red, Green, Blue, [Display(Description = "Almond Green")] AlmondGreen, [Display(Description = "Amber Gray")] AmberGray, [Display(Description = "Apple Blue... ")] AppleBlueSeaGreen, [Display(Description = "Azure")] AzureBlue, } public enum StatusType { Inactive, Active, } protected override void OnInitialized() { initialEmployees = Enumerable.Range(0, 10).Select(i => new Employee { ID = i, Gender = i < 3 ? GenderType.Mr : i < 6 ? GenderType.Ms : GenderType.Unknown, Status = i < 3 ? StatusType.Active : i < 6 ? StatusType.Inactive : null, Color = i < 3 ? [_allColors[0].Value, _allColors[2].Value] : i < 6 ? [_allColors[1].Value, _allColors[3].Value] : [_allColors[4].Value, _allColors[6].Value], }); } void LoadData(LoadDataArgs args) { isLoading = true; console.Log($"LoadData. {DateTime.Now.ToLongTimeString()}"); var query = initialEmployees.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(args.Filter); } if (!string.IsNullOrEmpty(args.OrderBy)) { query = query.OrderBy(args.OrderBy); } count = query.Count(); employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); isLoading = false; } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 18:20:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#2900