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

How To Set Initial Sort

6 Answers 177 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 21 Jul 2010, 12:16 AM
Hi,

I'm trying to specify which column should be the column which is the one that the Grid is initially sorted by. I'm hoping there's a property we can set to do this declaratively. I tried setting the SortingState property of the data column but it didn't do anything.

I'd rather do it through the grid rather than just sorting the list myself before setting it as the Grid's source so that the user gets a visual cue (the little triangle which shows on top of the column) as to which column is sorted and in what direction.

Thanks,

Carlos

6 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 21 Jul 2010, 05:35 AM
Hi Carlos Santos,

You can simply add a SortDescriptor to your RadGridView definition in XAML:

<telerik:RadGridView Name="playersGrid" 
                             ItemsSource="{Binding Players}" 
                             AutoGenerateColumns="False">
      
    <telerik:RadGridView.SortDescriptors>
        <telerik:SortDescriptor Member="Name" SortDirection="Ascending"/>
    </telerik:RadGridView.SortDescriptors>
      
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>


Sincerely yours,
Milan
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
0
Carlos
Top achievements
Rank 1
answered on 21 Jul 2010, 05:51 AM
Great, thanks for the quick reply.
0
Uli
Top achievements
Rank 1
answered on 04 Aug 2010, 07:38 AM
Hi,

I have a similar situation. I also want to give the user a hint of the initial sorting. The solution you suggested can't be used in my case because I want to do custom sorting. That means I can't provide SortDescriptors.

Any other suggestions?

Regards,

Uli
0
Milan
Telerik team
answered on 04 Aug 2010, 07:50 AM
Hello Uli,

You can use the DataLoaded event to initialize the sorting state of some columns

void clubsGrid_DataLoaded(object sender, EventArgs e)
{
    this.clubsGrid.Columns[1].SortingState = SortingState.Ascending;
}


Greetings,
Milan
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
0
Uli
Top achievements
Rank 1
answered on 04 Aug 2010, 08:02 AM
Hi Milan,

thanks for your really quick reply. But it does not work. I already tried before to set the sorting state of a column. This state is not reflected in the UI.

Perhaps I have to mention that I am not working with Silverlight but with WPF.

Regards Uli
0
Uli
Top achievements
Rank 1
answered on 04 Aug 2010, 08:45 AM
Hi Milan,

my sample contains also a Loaded-handler of the parent control of the RadGridView. In this handler the ItemsSource collection of the RadGridView is changed again, causing another change of the SortingState property. If I avoid this, the solution you suggested works.

I do some more investigation. Currently I think I can use your solution.

Thanks

Uli
Tags
GridView
Asked by
Carlos
Top achievements
Rank 1
Answers by
Milan
Telerik team
Carlos
Top achievements
Rank 1
Uli
Top achievements
Rank 1
Share this question
or