Unplanned
Last Updated: 16 Mar 2023 16:20 by Teddy
Scofield
Created on: 16 Mar 2023 16:05
Category: DataGrid
Type: Feature Request
4
DataGrid: Provide a nested property sort descriptor for TemplateColumn

Provide an option to sort the template column by nested property. 

For example: 

<dataGrid:DataGridTemplateColumn>
    <dataGrid:DataGridTemplateColumn.CellContentTemplate>
        <DataTemplate>
            <Label Text="{Binding MyAddress.City}" />
        </DataTemplate>
    </dataGrid:DataGridTemplateColumn.CellContentTemplate>
    <dataGrid:DataGridTemplateColumn.SortDescriptor>
        <dataGrid:PropertySortDescriptor PropertyName="MyAddress.City"  />
    </dataGrid:DataGridTemplateColumn.SortDescriptor>
</dataGrid:DataGridTemplateColumn>

1 comment
Teddy
Posted on: 16 Mar 2023 16:20

Let me add a bit more information with some sample code:

public class OuterClass
{
    public InnerClass InnerObject { get; set; }

    public int InnerSortProp => InnerObject.SortProp;
}

public class InnerClass
{
    public int SortProp { get; set; }
}
    <dataGrid:RadDataGrid ItemsSource="{Binding ItemsSource, Source={x:Reference This}}"
                          AutoGenerateColumns="False">
        <dataGrid:RadDataGrid.Columns>
            <!--<dataGrid:DataGridNumericalColumn HeaderText="Regular Numeric Column"
                                              PropertyName="InnerObject.SortProp"/>-->
            <dataGrid:DataGridTemplateColumn HeaderText="Sortable">
                <dataGrid:DataGridTemplateColumn.CellContentTemplate>
                    <DataTemplate>
                        <Label x:DataType="telerikScratch:OuterClass"
                               Text="{Binding InnerObject.SortProp}" />
                    </DataTemplate>
                </dataGrid:DataGridTemplateColumn.CellContentTemplate>
                <dataGrid:DataGridTemplateColumn.SortDescriptor>
                    <dataGrid:PropertySortDescriptor PropertyName="InnerSortProp"/>
                </dataGrid:DataGridTemplateColumn.SortDescriptor>
            </dataGrid:DataGridTemplateColumn>
            <dataGrid:DataGridTemplateColumn HeaderText="Not Sortable">
                <dataGrid:DataGridTemplateColumn.CellContentTemplate>
                    <DataTemplate>
                        <Label x:DataType="telerikScratch:OuterClass"
                               Text="{Binding InnerObject.SortProp}" />
                    </DataTemplate>
                </dataGrid:DataGridTemplateColumn.CellContentTemplate>
                <dataGrid:DataGridTemplateColumn.SortDescriptor>
                    <dataGrid:PropertySortDescriptor PropertyName="InnerObject.SortProp"/>
                </dataGrid:DataGridTemplateColumn.SortDescriptor>
            </dataGrid:DataGridTemplateColumn>
        </dataGrid:RadDataGrid.Columns>
    </dataGrid:RadDataGrid>

So notice above that both uncommented columns are template columns that show InnerObject.SortProp. But one has a sort descriptor that points to a getter property that accesses InnerObject.SortProp, while another references InnerObject.SortProp directly

You'll notice that you can sort the first column without issue. But if you try to sort the 2nd column, the grid goes white and shows a busy indicator indefinitely. 

But... if you then uncomment the numerical column that's bound directly to InnerObject.SortProp, then you can sort that same column without issue.

So the issue seems to be, you can't set a nested property as a sort descriptor, unless you also happen to have another column that's already bound to that nested property (Note the column doesn't need to be visible. If you set the numerical column's IsVisible=False, then the last column is still sortable). Or, you have to add an accessor property at the root object, since the properties directly on the bound object don't have this limitation.