Datagrid sort by

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.

<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?

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

Custom method it is then
Thanks

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?

public string newProperty 
{ 
          get
          {
                 return this.TableB?.Count();
          }
}
<RadzenDataGridColumn 
          TItem="EsWlite.Models.Ecosys.TableA"
          Property="newProperty" 
          FilterProperty="newProperty "
          SortProperty="newProperty " 
          Title="Class">
</RadzenDataGridColumn>
1 Like