# Datagrid sort by

**URL:** <https://forum.radzen.com/t/datagrid-sort-by/15839>\
**Category:** Radzen.Blazor Components\
**Created:** [December 6, 2023, 10:05am UTC](https://forum.radzen.com/t/datagrid-sort-by/15839 "2023-12-06T10:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnmu](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@johnmu](https://forum.radzen.com/u/johnmu)\
**Post date:** [December 6, 2023, 10:05am UTC](https://forum.radzen.com/t/datagrid-sort-by/15839/1 "2023-12-06T10:05:44Z")

</div>

I have a table (Table A) with a related child (Table B) and in the datagrid I am showing the records from Table A and the count of the related children from table B. Now i need to sort and filter on this count but i can't get the syntax right.

```auto
<RadzenDataGrid @ref="grid0" 
       AllowFiltering="true" 
       AllowSorting="true" 
       Data="@TableAResult" 
       TItem="EsWlite.Models.Ecosys.TableA" 
       >
  <RadzenDataGridColumn 
          TItem="EsWlite.Models.Ecosys.TableA" 
          FilterProperty="TableC.Unit" Groupable="false" 
          Property="DefaultUnits" 
          SortProperty="TableC.Unit" 
          Title="Unit">
  <Template Context="data">
       @(data.TableC?.Unit)
  </Template>
</RadzenDataGridColumn>
    <RadzenDataGridColumn 
          TItem="EsWlite.Models.Ecosys.TableA"

          <!--Throws an error on rendering
          I have tried various combo's of this but not foud a working solution
          -->

          FilterProperty="TableB.ToList().Count().ToString()"
          SortProperty="TableB.ToList().Count().ToString()" 
          Title="Class">

      <Template Context="data">
      @(data.TableB?.Count())
      </Template>
    </RadzenDataGridColumn>

```

Is there a way or do i have to create a custom method and build the datagrid around a new class?

---

<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:** [December 6, 2023, 10:36am UTC](https://forum.radzen.com/t/datagrid-sort-by/15839/2 "2023-12-06T10:36:37Z")

</div>

There is no way to sort by such expression, only by property name.

---

<div class="post-metadata">

**Author:** ![johnmu](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@johnmu](https://forum.radzen.com/u/johnmu)\
**Post date:** [December 6, 2023, 10:38am UTC](https://forum.radzen.com/t/datagrid-sort-by/15839/3 "2023-12-06T10:38:43Z")

</div>

Custom method it is then  
Thanks

---

<div class="post-metadata">

**Author:** ![GodzSky](https://forum.radzen.com/user_avatar/forum.radzen.com/godzsky/32/10735_2.png) [@GodzSky](https://forum.radzen.com/u/GodzSky)\
**Post date:** [December 6, 2023, 11:05am UTC](https://forum.radzen.com/t/datagrid-sort-by/15839/4 "2023-12-06T11:05:32Z")

</div>

Maybe u can try to add a property to ur class (EsWlite.Models.Ecosys.TableA) where in the get u read that Count and then u use that property as column?

```auto
public string newProperty 
{ 
          get
          {
                 return this.TableB?.Count();
          }
}

```

```auto
<RadzenDataGridColumn 
          TItem="EsWlite.Models.Ecosys.TableA"
          Property="newProperty" 
          FilterProperty="newProperty "
          SortProperty="newProperty " 
          Title="Class">
</RadzenDataGridColumn>

```
