=== EDITED BY TELERIK ===
When using nullable enums, their DisplayNameAttrute doesn't show in the Grid.
https://blazorrepl.telerik.com/QTOlwiaM456Yh9Xp33
The bug is related to Enum DisplayName attributes are ignored in view mode of the Grid
=== ORIGINAL POST CONTENT ===
Sample Code to reproduce the error:
https://blazorrepl.telerik.com/QzYPGLFj11s0rZwp47
If you change line 44 to a non-nullable field type, it crashes the grid with an error message in the CSS file. I have included the error message I get in my blazor app with the same code above, console then sources:
Hello Peter,
Thanks for the runnable test page. Here are my observations:
PayCodeClassType is defined like this:
public enum PayCodeClassType
{
Hourly = 'H',
Salary = 'S',
Piecework = 'P',
Commission = 'C',
Bonus = 'B'
}
One of the Grid data items is defined like this:
public List<PayCode> Data { get; set; } = new()
{
new PayCode { Id = 5, ClassType = 0, /* ... */ }
};
So, the data item contains a non-existent PayCodeClassType value. As a result, the following exception occurs, which points to an issue with an enum value (see the attached enum-exception.png):
System.IndexOutOfRangeException: Index was outside the bounds of the array. at Telerik.Blazor.Extensions.EnumExtensions.GetEnumValueDisplayName(Object enumValue)
The difference between nullable and non-nullable enums is that nullable enum types return false for Type.IsEnum, while the Grid assumes the opposite. With nullable enums, GetEnumValueDisplayName() is not used and that's why there is no error.
In other words, this recent fix needs to be enhanced for nullable enums too.
I believe the CSS browserLink error is a false positive with regard to the discussed scenario. The real exception is not visible on your side, because detailedErrors are not enabled in the app. However, the enum exception should be visible in the Visual Studio's output window (see the attached vs-output-window.png).
>> IMHO, we need either a better error message caught in the Grid control or fix it so it behaves like when we use a nullable ENUM object for a grid column field.
We believe the current error handling is enough as is. The second suggestion about consistent behavior is certainly valid, but the other way around - the Grid should throw also with a nullable enum type, when the provided value is invalid.
In conclusion, I edited this bug report's title and description to match the actual problem that we intend to resolve.
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.