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

Sort column by multiple criteria

1 Answer 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Todor
Top achievements
Rank 1
Todor asked on 06 Jul 2010, 01:01 PM
Hello,

I have a question regarding sorting of a GridViewDataColumn.
Here is the column definition:
  <telerik:GridViewDataColumn IsReadOnly="True" 
                                                                Header="ELEMENT" 
                                                                DataMemberBinding="{Binding Name}" 
                                                                SortMemberPath="ElementType" 
                                                                Width="*"
                                        <telerik:GridViewDataColumn.CellTemplate> 
                                            <DataTemplate> 
                                                <StackPanel Orientation="Horizontal"
                                                    <Image Source="{Binding ElementType, Converter={StaticResource ElementImageConverter}}" /> 
                                                    <TextBlock Text="{Binding Name}" 
                                                                              Margin="3,0,0,0" 
                                                                              VerticalAlignment="Center" /> 
                                                </StackPanel> 
                                            </DataTemplate> 
                                        </telerik:GridViewDataColumn.CellTemplate> 
                                    </telerik:GridViewDataColumn> 

The ElementType is Enum and the Name is String.
I have two questions:

1) I want the main criteria for sorting the column to be the ElementType, not the name. If I put the ElementType in the DataMemberBinding, then it works, but when I change the Names of the elements outside of the grid, they don't get refreshed (the PropertyChanged event is not handled). When I set the DataMemeberBinding to Name, the refresh is OK. How can I fix that ?

2) I want to make a second criteria for the sort, so that when I sort the elements of one type, are also sorted by Name.

Thanks !

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 06 Jul 2010, 01:09 PM
Hello Todor,

One of the possible solutions would be to use custom sorting:
This means subscribing to the RadGridView.Sorting event, canceling the default sort  and  performing your own sort of the collection inside the event handler.
A demo with some sample  code you can find here.

A cheap alternative would be to modify your business object so it could raise the NotifyPropertyChanged event for the Name property, when the ElementType property has changed.

All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Todor
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or