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

Cannot sort numerical data column

2 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Søren
Top achievements
Rank 1
Søren asked on 30 Jul 2012, 08:40 AM
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 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Jul 2012, 08:42 AM
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.

0
Søren
Top achievements
Rank 1
answered on 30 Jul 2012, 10:05 AM
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
Tags
GridView
Asked by
Søren
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Søren
Top achievements
Rank 1
Share this question
or