From a56981bc7038e68536024414af7af09f74ad194d Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Mon, 18 Nov 2024 10:28:53 +0200 Subject: [PATCH] RadzenDataFilterProperty FilterProperty property added similar to DataGrid columns to be able to filter collection sub property Fix #1792 --- Radzen.Blazor/QueryableExtension.cs | 39 +++++++++++++++++-- Radzen.Blazor/RadzenDataFilterProperty.cs | 7 ++++ .../Pages/DataFilterIQueryable.razor | 9 ++++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Radzen.Blazor/QueryableExtension.cs b/Radzen.Blazor/QueryableExtension.cs index e9d3971c726..7c688b44b6a 100644 --- a/Radzen.Blazor/QueryableExtension.cs +++ b/Radzen.Blazor/QueryableExtension.cs @@ -1133,8 +1133,16 @@ private static void AddWhereExpression(Func if (IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string) && comparison == "Contains") { - filterExpressions.Add($@"(@{index}).Contains({property})"); - filterValues.Add(new object[] { filter.FilterValue }); + if (column.Property != column.FilterProperty && !string.IsNullOrEmpty(column.FilterProperty)) + { + filterExpressions.Add($@"{column.Property}.Any(i => i.{column.FilterProperty}{filterCaseSensitivityOperator}.Contains(@{index}{filterCaseSensitivityOperator}))"); + filterValues.Add(new object[] { filter.FilterValue }); + } + else + { + filterExpressions.Add($@"(@{index}).Contains({property})"); + filterValues.Add(new object[] { filter.FilterValue }); + } } else { @@ -1153,8 +1161,16 @@ private static void AddWhereExpression(Func if (IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string) && comparison == "DoesNotContain") { - filterExpressions.Add($@"!(@{index}).Contains({property})"); - filterValues.Add(new object[] { filter.FilterValue }); + if (column.Property != column.FilterProperty && !string.IsNullOrEmpty(column.FilterProperty)) + { + filterExpressions.Add($@"!{column.Property}.Any(i => i.{column.FilterProperty}{filterCaseSensitivityOperator}.Contains(@{index}{filterCaseSensitivityOperator}))"); + filterValues.Add(new object[] { filter.FilterValue }); + } + else + { + filterExpressions.Add($@"!(@{index}).Contains({property})"); + filterValues.Add(new object[] { filter.FilterValue }); + } } else { @@ -1173,6 +1189,21 @@ private static void AddWhereExpression(Func index++; } + else if (IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string) && + column.Property != column.FilterProperty && !string.IsNullOrEmpty(column.FilterProperty)) + { + filterExpressions.Add($@"{(comparison == "NotIn" ? "!" : "")}{column.Property}.Any(i => i.{column.FilterProperty} in @{index})"); + filterValues.Add(new object[] { filter.FilterValue }); + + index++; + } + } + else if (IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string) && column.Property != column.FilterProperty && !string.IsNullOrEmpty(column.FilterProperty)) + { + filterExpressions.Add($@"{column.Property}.Any(i => i.{column.FilterProperty}{filterCaseSensitivityOperator} {comparison} @{index}{filterCaseSensitivityOperator})"); + filterValues.Add(new object[] { filter.FilterValue }); + + index++; } else if (!(IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string))) { diff --git a/Radzen.Blazor/RadzenDataFilterProperty.cs b/Radzen.Blazor/RadzenDataFilterProperty.cs index f3c01a439f5..1d686be980f 100644 --- a/Radzen.Blazor/RadzenDataFilterProperty.cs +++ b/Radzen.Blazor/RadzenDataFilterProperty.cs @@ -118,6 +118,13 @@ internal void SetVisible(bool? value) [Parameter] public string Property { get; set; } + /// + /// Gets or sets the filter property name. + /// + /// The filter property name. + [Parameter] + public string FilterProperty { get; set; } + /// /// Gets or sets a value indicating whether this property is selected in the filter. /// diff --git a/RadzenBlazorDemos/Pages/DataFilterIQueryable.razor b/RadzenBlazorDemos/Pages/DataFilterIQueryable.razor index 6f11c3283d4..7d26ac277d6 100644 --- a/RadzenBlazorDemos/Pages/DataFilterIQueryable.razor +++ b/RadzenBlazorDemos/Pages/DataFilterIQueryable.razor @@ -11,7 +11,7 @@ - + @@ -27,6 +27,8 @@ Change=@OnSelectedProductIdsChange Data="@(productIds)" AllowClear="true" Multiple="true" /> + @@ -46,6 +48,11 @@ Displayed orders: @ordersGrid.View.Count() of @orders.Count() + + +