Cannot sort numerical data column

3 posts, 0 answers
  1. Søren
    Søren avatar
    2 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2012 Link to this post

    I have a RadGridView with the following properties:

    telerik:RadGridView x:Name="SearchResult_DataGrid"
     Grid.Row="2"
     AutoGenerateColumns="False"
     IsReadOnly="True"
     RowIndicatorVisibility="Collapsed"
     CanUserFreezeColumns="False"
     CanUserResizeColumns="False"
     DataContext="{Binding}"
     ItemsSource="{Binding Path=Data}"
     SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}"
     MouseRightButtonDown="SearchResult_DataGrid_MouseRightButtonDown"
     ShowGroupPanel="False" >
    <telerik:RadGridView.Columns>
     <telerik:GridViewDataColumn DataMemberBinding="{Binding Date}" Header="Date"/> 
     <telerik:GridViewDataColumn Header="Week" DataMemberBinding="{Binding Week}" />
    </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    When I try to sort by week, I get the "classic" string-sort problem, e.g.

    10
    11
    4
    42
    7

    I've tried setting the DataType programatically:

    var column = SearchResult_DataGrid.Columns["Week"] as Telerik.Windows.Controls.GridViewBoundColumnBase;
    if (column != null)
    {
      column.DataType = typeof(int);
    }

    But it doesn't help.
    I've searched high and low in the forum and stumbled upon someone mentioning a numerical column, but I can't find that in the documentation. It seems a bit overkill to make custom sorting on a column that contain integers, so I would very much like to find a solution to this problem, since I have other columns with the same problem.

    So - how do I sort a column based on numerical values?

    I'm using the Q3 2011 version

    Best regards
    Søren Hansen
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Jul 2012 Link to this post

    Hi,

     Changing DataType property of the grid column will not change your underlying data data type. You cannot sort strings as numeric!

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Søren
    Søren avatar
    2 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2012 Link to this post

    Thank you for the quick response!

    I've changed the underlying data type to int, and now it sorts as expected. The reason it was a string before, was to enable error messages, which has now been moved.

    /Søren
Back to Top