Skip to content

Commit

Permalink
Fixed DataGrid CheckBoxList filtering with LoadData for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
enchev committed Dec 19, 2024
1 parent 1ceaab2 commit d216973
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions Radzen.Blazor/QueryableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ public static IList ToList(IQueryable query)
return (IList)genericToList.Invoke(null, new[] { query });
}

static string EnumerableAsString(IQueryable enumerableValue, string baseType)
{
Func<IQueryable, IEnumerable<object>> values = (items) => {
if (items.ElementType == typeof(string))
{
return items.Cast<string>().Select(i => $@"""{i}""");
}
else if (PropertyAccess.IsDate(items.ElementType))
{
return items.Cast<object>().Select(i => $@"DateTime.Parse(""{i}"")");
}
else if (PropertyAccess.IsEnum(items.ElementType) || PropertyAccess.IsNullableEnum(items.ElementType))
{
return items.Cast<object>().Select(i => Convert.ChangeType(i,typeof(int)));
}

return items.Cast<object>();

};
return "new " + baseType + "[]{" + String.Join(",", values(enumerableValue)) + "}";
}

/// <summary>
/// Converts to filterstring.
/// </summary>
Expand Down Expand Up @@ -177,29 +199,9 @@ public static string ToFilterString<T>(this IEnumerable<RadzenDataGridColumn<T>>
baseType = "";
}

var enumerableValueAsString = "new " + baseType + "[]{" + String.Join(",",
(enumerableValue.ElementType == typeof(string)
? enumerableValue.Cast<string>().Select(i => $@"""{i}""")
.Cast<object>()
: PropertyAccess.IsDate(enumerableValue.ElementType)
? enumerableValue.Cast<object>()
.Select(i => $@"DateTime.Parse(""{i}"")")
.Cast<object>()
: enumerableValue.Cast<object>()
)) + "}";


var enumerableSecondValueAsString = "new " + baseType + "[]{" + String.Join(",",
(enumerableSecondValue.ElementType == typeof(string)
? enumerableSecondValue.Cast<string>()
.Select(i => $@"""{i}""").Cast<object>()
: PropertyAccess.IsDate(
enumerableSecondValue.ElementType)
? enumerableSecondValue.Cast<object>()
.Select(i => $@"DateTime.Parse(""{i}"")")
.Cast<object>()
: enumerableSecondValue.Cast<object>()
)) + "}";
var enumerableValueAsString = EnumerableAsString(enumerableValue, baseType);

var enumerableSecondValueAsString = EnumerableAsString(enumerableSecondValue, baseType);

if (enumerableValue?.Any() == true)
{
Expand Down

0 comments on commit d216973

Please sign in to comment.