Sort dynamic data with ColumnSortDescriptor

2 posts, 0 answers
  1. Stavroula
    Stavroula avatar
    5 posts
    Member since:
    Sep 2011

    Posted 21 Feb 2013 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Feb 2013 Link to this post

    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.

Back to Top