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

Sort dynamic data with ColumnSortDescriptor

1 Answer 218 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stavroula
Top achievements
Rank 1
Stavroula asked on 21 Feb 2013, 02:10 PM
Hallo Telerik,

I want to sort the Rows in my Grid. I have accomplished this with the event handler "RadGridView_Sorting". My data are all strings, so I use an IComparer to sort the data (Integers) and then bind them to the RadGridView.
My data is sorted when I load the data for the first time, but the GridView doesn't show the sorted Column. With the following code, I get the sorted column. 
<telerik:RadGridView.SortDescriptors>
        <telerik:ColumnSortDescriptor Column="{Binding Columns[\Title\], ElementName=radGridView}" SortDirection="Ascending"/>
    </telerik:RadGridView.SortDescriptors>

Can I use the code with dynamic binding of the column? For example something like this:
<telerik:RadGridView.SortDescriptors>
        <telerik:ColumnSortDescriptor Column="{Binding Columns[\{Binding SortMember}\], ElementName=radGridView}" SortDirection="{Binding SortDirection}"/>
    </telerik:RadGridView.SortDescriptors>

When I bind the SortDirection, it works. But how can I bind the column to be sorted dynamically?

One more question: I have the data of the RadGridView bound to a collection in MVVM. When I load the RadGridView for the first time, I expect the sorting_event to be called. Why does it not happen? 

Best Regards

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Feb 2013, 03:48 PM
Hello,

What do you mean that the GridView does not show the sorted column? Have you defined such a column? Would you please share the code for your column's definition? An image showing the result you got would be helpful as well.

Generally the Sorting event is a UI event and it will be raised only based on user interaction, i.e. when the user clicks on the column's header to invoke sorting. 

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Stavroula
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or