DateTime column Sorting problem not correct

2 posts, 0 answers
  1. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 03 Jul 2013 Link to this post

    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.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Jul 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top