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

DateTime column Sorting problem not correct

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 2
Manish asked on 03 Jul 2013, 10:23 AM

Hi,
I have a column StartDate type Datetime. But when i click on column header for sorting it is not sorting properly in acs or desc. it is showing sorting only on month part of date
Like
08/21/2012
07/21/2014
06/26/2013
06/26/2013
It is in descending order but it is wrong.

<telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate" DataType="System.DateTime"
UniqueName="StartDate"DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true"
 ItemStyle-Width="80px" HeaderStyle-Width="80px">
</telerik:GridBoundColumn>
I have tried this http://www.telerik.com/community/forums/aspnet-ajax/grid/sort-the-date-column-in-radgrid-on-clicking-of-the-header.aspx but still no success. Please find screen shot of problem.

I also used
<telerik:GridDateTimeColumn DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate"
DataType="System.DateTime" UniqueName="StartDate" DataFormatString="{0:MM/dd/yyyy}"
ReadOnly="true" ItemStyle-Width="80px" HeaderStyle-Width="80px">
</telerik:GridDateTimeColumn>
 But not working Please help.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Jul 2013, 10:52 AM
Hello,

I am not able to reproduce this issue.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
AllowSorting="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
                <telerik:GridDateTimeColumn DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate"
                    DataType="System.DateTime" UniqueName="StartDate" DataFormatString="{0:MM/dd/yyyy}"
                    ReadOnly="true" ItemStyle-Width="80px" HeaderStyle-Width="80px">
                </telerik:GridDateTimeColumn>
                <telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate"
                    DataType="System.DateTime" UniqueName="StartDate1" DataFormatString="{0:MM/dd/yyyy}"
                    ReadOnly="true" ItemStyle-Width="80px" HeaderStyle-Width="80px">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data = new[] {
           new { ID = 1, Name ="Name1",StartDate = DateTime.Now.AddMonths(5)},
           new { ID = 2, Name = "Name2",StartDate = DateTime.Now.AddMonths(-5)},
           new { ID = 3, Name = "Name3",StartDate = DateTime.Now.AddMonths(-28)},
            new { ID = 4, Name = "Name4",StartDate = DateTime.Now.AddMonths(-15)},
           new { ID = 5, Name = "Name5",StartDate = DateTime.Now.AddMonths(50)}
       };
 
       RadGrid1.DataSource = data;
   }

My TimeZone : IST


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Manish
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or