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

Column Sorting, DateTime & Double

2 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emma Rennie
Top achievements
Rank 1
Emma Rennie asked on 07 Jan 2010, 10:03 PM
I am using RadGrid version 2009.3.1208.35. All code is below.

When I set the Date column as DataType="System.DateTime" it still does not seem to sort correctly. If i set the Column type to DateTime, ie "dt.Columns.Add("Date", typeof(DateTime));" it works. Is there any way to have correct sorting without having to do this?



    protected void gv_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
      DataTable dt = new DataTable(); 
      dt.Columns.Add("Date"); 
      dt.Columns.Add("Double"); 
      dt.Rows.Add(new object[] {"14/08/2009","1.1" }); 
      dt.Rows.Add(new object[] { "20/08/2009""10.1" }); 
      dt.Rows.Add(new object[] { "10/09/2009""2.1" }); 
      dt.Rows.Add(new object[] { "25/09/2008""2.1" }); 
      dt.Rows.Add(new object[] { "25/11/2009""2.1" }); 
      dt.Rows.Add(new object[] { "1/1/2009""2.1" }); 
 
      rg.DataSource = dt; 
    } 


    <telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false" OnNeedDataSource="gv_NeedDataSource" 
      AllowSorting="true"
      <MasterTableView> 
        <Columns> 
          <telerik:GridBoundColumn DataType="System.DateTime" HeaderText="Date" DataField="Date" 
            UniqueName="Date" DataFormatString="{0:MM/yyyy}"
          </telerik:GridBoundColumn> 
          <telerik:GridBoundColumn DataType="System.Double" HeaderText="Double" DataField="Double" 
            ItemStyle-HorizontalAlign="Right"
          </telerik:GridBoundColumn> 
        </Columns> 
      </MasterTableView> 
    </telerik:RadGrid> 




2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Jan 2010, 08:29 AM
Hi Nataliya,

Actually this is expected behavior due to the fact that you are supplying neither a DateTime or a Numeric but a string value, therefore it will be sorted as a string. Thus you should explicitly declare and supply the correct value types.

Regards,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
whidbey boy
Top achievements
Rank 1
answered on 24 Jun 2010, 06:23 PM
Please ignore this post.

Tags
Grid
Asked by
Emma Rennie
Top achievements
Rank 1
Answers by
Rosen
Telerik team
whidbey boy
Top achievements
Rank 1
Share this question
or