microsoft / fluentui-blazor

Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
https://www.fluentui-blazor.net
MIT License
3.23k stars 294 forks source link

fix: error when sorting a DataGrid column with mixed types #1957

Closed verdie-g closed 3 weeks ago

verdie-g commented 3 weeks ago

πŸ› Bug Report

Assuming you have a column with ints and string, clicking on the header on the column to sort it will throw a System.ArgumentException: Object must be of type Int32.

πŸ’» Repro or Code Sample

<FluentDataGrid Items="@people">
    <PropertyColumn Property="@(p => p.O)" Sortable="true" />
</FluentDataGrid>

@code {

    record Person(object O);

    IQueryable<Person> people = new[]
    {
        new Person(10895),
        new Person(10944),
        new Person(""),
    }.AsQueryable();

}

πŸ€” Expected Behavior

Not sure, but the component should probably not crash.

😯 Current Behavior

Blank page with an error image

πŸ’ Possible Solution

I suppose it can be considered as a mistake of the developer to have mixed types in a sortable column so maybe the exception should be caught and the sort canceled.

πŸ”¦ Context

I have a table of logs, and some logs may not contain all the fields so a "" value is used. I realize that a null value work around the issue.

🌍 Your Environment

vnbaaij commented 3 weeks ago

Yeah, I don't think we are going to cater for that. It is indeed a mistake of the developer which they can (and should) work around. Canceling the sort is not that easy