Empty DataGrid with FilterOperator="FilterOperator.In" and Type="typeof(IEnumerable<Enum>)"> #1613

Closed
opened 2026-01-29 17:56:14 +00:00 by claunia · 3 comments
Owner

Originally created by @k-Sacr on GitHub (Feb 14, 2025).

https://github.com/user-attachments/assets/9add47ae-174e-4bb2-917a-16bc0f652a72

Old pull request for fixes, maybe this will help: https://github.com/radzenhq/radzen-blazor/pull/1794

Demo code:

@using System.ComponentModel.DataAnnotations
@using Radzen.Blazor

@inject IJSRuntime JSRuntime

<RadzenDataGrid @ref="grid" 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;
    RadzenDataGrid<Employee> grid;

	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 ? new List<ColorType> { _allColors[0].Value, _allColors[2].Value }
       : i < 6 ? new List<ColorType> { _allColors[1].Value, _allColors[3].Value }
       : new List<ColorType> { _allColors[4].Value, _allColors[6].Value }

				});
	}

	void LoadData(LoadDataArgs args)
	{
		isLoading = true;
		
		var query = initialEmployees.AsQueryable();

		if (!string.IsNullOrEmpty(args.Filter))
		{
			query = query.Where(grid.ColumnsCollection);
            console.Log($"args.Filter. {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;

	}
}
Originally created by @k-Sacr on GitHub (Feb 14, 2025). https://github.com/user-attachments/assets/9add47ae-174e-4bb2-917a-16bc0f652a72 Old pull request for fixes, maybe this will help: https://github.com/radzenhq/radzen-blazor/pull/1794 Demo code: ``` @using System.ComponentModel.DataAnnotations @using Radzen.Blazor @inject IJSRuntime JSRuntime <RadzenDataGrid @ref="grid" 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; RadzenDataGrid<Employee> grid; 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 ? new List<ColorType> { _allColors[0].Value, _allColors[2].Value } : i < 6 ? new List<ColorType> { _allColors[1].Value, _allColors[3].Value } : new List<ColorType> { _allColors[4].Value, _allColors[6].Value } }); } void LoadData(LoadDataArgs args) { isLoading = true; var query = initialEmployees.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(grid.ColumnsCollection); console.Log($"args.Filter. {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; } } ```
Author
Owner

@enchev commented on GitHub (Feb 14, 2025):

This is what I see using the latest version:

Image

Image

@enchev commented on GitHub (Feb 14, 2025): This is what I see using the latest version: ![Image](https://github.com/user-attachments/assets/a804a8ec-5019-46e6-a98d-80d7e078431a) ![Image](https://github.com/user-attachments/assets/00d19069-1c66-4c32-a68c-259702048c19)
Author
Owner

@k-Sacr commented on GitHub (Feb 14, 2025):

This is what I see using the latest version:

I opened https://blazor.radzen.com/datagrid-advanced-filter and replaced the code in "edit source"
The filter works, but if you don't clear all filter, you remove the check from each checkbox, then you get an empty list.

@k-Sacr commented on GitHub (Feb 14, 2025): > This is what I see using the latest version: I opened https://blazor.radzen.com/datagrid-advanced-filter and replaced the code in "edit source" The filter works, but if you don't clear all filter, you remove the check from each checkbox, then you get an empty list.
Author
Owner

@enchev commented on GitHub (Feb 14, 2025):

Ah, I saw the problem - in some cases will return empty string lambda as Filter. Will be fixed immediately!

@enchev commented on GitHub (Feb 14, 2025): Ah, I saw the problem - in some cases will return empty string lambda as Filter. Will be fixed immediately!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1613