This is a migrated thread and some comments may be shown as answers.

Custom Sorting on Complex Object

1 Answer 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 15 Mar 2011, 06:41 PM
We have a data column that is databound to an object (rather than a value) to allow for multiple databindings in the cell template.  Sorting doesn't appear to work for this column because the sort function doesn't know what value to apply the sort to.
<telerikGridView:GridViewDataColumn Header="Region" UniqueName="Region" DataMemberBinding="{Binding Path=.}" IsSortable="True">
                                <telerikGridView:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Button Style="{StaticResource EyeGlassButtonStyle}" Margin="5,0,10,0" Command="{Binding Path=VM.GetContentCommand}" CommandParameter="{Binding ContentId}" />
                                            <HyperlinkButton Content="{Binding Label}" Command="{Binding Path=VM.GetContentCommand}" CommandParameter="{Binding ContentId}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </telerikGridView:GridViewDataColumn.CellTemplate>
                            </telerikGridView:GridViewDataColumn>



We added a Sorting event to the RadGridView and this column never fires the event.  The other columns (which are using doubles as values) are able to fire the event.  How can we apply a custom sort on this column to databind to the Item but sort by the Item's "Label" property?

1 Answer, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 15 Mar 2011, 07:54 PM
Hello Mike,

 You need to set the SortMemberPath property of the column to "Label". Also, since you're binding the column to the data object for the entire row, you can use just GridViewColumn, instead of GridViewDataColumn. A cell in the GridViewColumn automatically inherits the DataContext of the row it is in.

 The Sorting event never fires for this column as most probably your data item does not implement IComparable. GridViewDataColumn checks if the data it's bound to implements this interface and only then it enables sorting on it. In any case, if you set the SortMemberPath property of the column, it should check the type of the property in specified in SortMemberPath, not the binding.

Kind regards,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question
or