# DataGrid Sort on Nullable Property

**URL:** <https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183>\
**Category:** Blazor Server\
**Created:** [October 13, 2021, 5:22pm UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183 "2021-10-13T17:22:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beeterry](https://forum.radzen.com/user_avatar/forum.radzen.com/beeterry/32/7007_2.png) [@beeterry](https://forum.radzen.com/u/beeterry)\
**Post date:** [October 13, 2021, 5:22pm UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183/1 "2021-10-13T17:22:02Z")

</div>

I have a column that's bound to a property, that is a class, that may be null and when I sort on that column if throws a null exception.

`Item.ClassProperty.Id`  
`<RadzenDataGridColumn TItem="Shipment" Property="Item.ClassProperty.Id" />`

Where `ClassProperty` could be null.

In theory, I feel like null values should just float to the top/bottom instead of throwing an exception. Is there anyway to allow nulls or am I going to have to create a sort property for each of my nullable paths on the Item itself?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [October 14, 2021, 11:49am UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183/2 "2021-10-14T11:49:21Z")

</div>

Can you post the stack trace?

---

<div class="post-metadata">

**Author:** ![beeterry](https://forum.radzen.com/user_avatar/forum.radzen.com/beeterry/32/7007_2.png) [@beeterry](https://forum.radzen.com/u/beeterry)\
**Post date:** [October 14, 2021, 12:08pm UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183/3 "2021-10-14T12:08:26Z")

</div>

Does this help?

```auto
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Arg_NullReferenceException
System.NullReferenceException: Arg_NullReferenceException
   at System.Linq.EnumerableSorter`2[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ComputeKeys(Shipment[] elements, Int32 count)
   at System.Linq.EnumerableSorter`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ComputeMap(Shipment[] elements, Int32 count)
   at System.Linq.EnumerableSorter`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Sort(Shipment[] elements, Int32 count)
   at System.Linq.OrderedEnumerable`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SortedMap(Buffer`1 buffer)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__17[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at System.Collections.Generic.List`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[Shipment](IEnumerable`1 source)
   at Radzen.PagedDataBoundComponent`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_PagedView()
   at Radzen.Blazor.RadzenDataGrid`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].DrawGroupOrDataRows(RenderTreeBuilder builder, IList`1 visibleColumns)
   at Radzen.Blazor.RadzenDataGrid`1.<>c__DisplayClass6_0[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<DrawRows>b__0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Radzen.Blazor.RadzenDataGrid`1[[Olis.Server.Core.Shipments.Shipment, Olis.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

```

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [October 14, 2021, 12:31pm UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183/4 "2021-10-14T12:31:36Z")

</div>

Just tried the following and it worked:

```auto
    <RadzenDataGrid AllowSorting="true" Data="@data" TItem="MyObject">
        <Columns>
            <RadzenDataGridColumn TItem="MyObject" Property="MySubProperty.Id" Title="Id" />
        </Columns>
    </RadzenDataGrid>
@code {
    IEnumerable<MyObject> data;

    protected override void OnInitialized()
    {
        data = Enumerable.Range(0,3).Select(i => new MyObject(){ Id = i, MySubProperty = i == 0 ? null : new MyObject() { Id = i } }).ToList();
    }

    public class MyObject
    {
        public int Id { get; set; }
        public MyObject MySubProperty { get; set; }
    }
}

```

 ![image](https://forum.radzen.com/uploads/default/original/2X/e/ee869868c4a10e298b0335488b8bc00ea127635b.png)

 ![image](https://forum.radzen.com/uploads/default/original/2X/d/d15004a2e2edd92e4c76275a82597d423633023c.png)

UPDATE: I was able to reproduce the exception with two levels of nesting - we will do our best to find a way to handle this in our next update:

 ![image](https://forum.radzen.com/uploads/default/original/2X/c/cbe566f1c97c43c2ace6ef2666839afcfeef6434.png)

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [October 14, 2021, 1:07pm UTC](https://forum.radzen.com/t/datagrid-sort-on-nullable-property/9183/5 "2021-10-14T13:07:00Z")

</div>

The fix will be released in the next update:

> <https://github.com/radzenhq/radzen-blazor/commit/2c93f6038ee6685796ea0eabecfa1ed3bf46038e>
