DateTime column Sorting problem - Please Urgent

9 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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2013 Link to this post

    Hi Manish,

    I tried to replicate the issue,but it works fine at my end. Can you try using GridDateTimeColumn instead of GridBoundColumn.
    I have tried using both and the sorting takes place fine.

    ASPX:
    <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>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 03 Jul 2013 Link to this post

    Hi Princy,

    Thanks for your quick reply. I have applied your code
    <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 still it is not working. When my data come from database and i have not apply any sorting from grid than it is working fine but when i am going to apply from column it shows wrong data. Please help still not working fine with your code as well.
  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 05 Jul 2013 Link to this post

    Hello Manish,

    I tried replicating the scenario displayed on the screenshot but to no avail. I used the same settings for the GridBoundColumn as the ones you have set. When the RadGrid is sorted it produces the expected result on my end - the whole date is taken into account. You would find a sample project attached. Give it a try and see if it is working as expected on your end.

    If you have custom sorting for the column, try disabling it and see if the result is different.

    Regards,
    Viktor Tachev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Shafqat
    Shafqat avatar
    3 posts
    Member since:
    Nov 2016

    Posted 24 Nov in reply to Viktor Tachev Link to this post

    i have sorting issue in Telerik radgrid on Date column, below is my code for radgrid 

         <telerik:radgrid id="gdshow" runat="server" width="100%" allowsorting="true" allowfilteringbycolumn="false"     OnNeedDataSource="gdshow_NeedDataSource"     OnItemCommand="gdshow_ItemCommand"
            OpenInNewWindow="true"     pagesize="20" allowmultirowselection="false" allowpaging="True" showgrouppanel="false" OnPageIndexChanged="gdshow_PageIndexChanged" OnPageSizeChanged="gdshow_PageSizeChanged" OnSortCommand="gdshow_SortCommand"
                gridlines="None" style="border: 0; outline: none;" itemstyle-forecolor="Black" headerstyle-font-bold="true" headerstyle-horizontalalign="left"
                itemstyle-horizontalalign="Center" headerstyle-forecolor="Black" ExportSettings-FileName="Custom Report" OnGridExporting="gdshow_GridExporting" ExportSettings-IgnorePaging="true">
                         <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                                                        <MasterTableView  CommandItemDisplay="Top" AllowMultiColumnSorting="true" PagerStyle-AlwaysVisible="true">
                                                            <ItemStyle CssClass="GridRow1" />
                                                           <AlternatingItemStyle CssClass="GridRow2" />  
                                                          
                                                                    <%-- <PagerStyle AlwaysVisible="true" ShowPagerText="false"      FirstPageImageUrl="../images/First.png" PrevPageImageUrl="../images/Per.png" NextPageImageUrl="../images/Next.png"  LastPageImageUrl="../images/Last.png" PageSizeLabelText="Show:" />--%>

                                                            <CommandItemTemplate>
                                                            </CommandItemTemplate>

                                                              </MasterTableView>
                                                             <ClientSettings>
                                                          <ClientEvents OnGridCreated="GridCreated" />
                                                     </ClientSettings>                                 
                                                
                        </telerik:radgrid>

  7. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 25 Nov Link to this post

    Hi Shafqat,

    Would you ensure that the field for the column showing the Date is actually a DateTime?

    If that is the case please send us a sample where the issue is replicated.


    Regards,
    Viktor Tachev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  8. Shafqat
    Shafqat avatar
    3 posts
    Member since:
    Nov 2016

    Posted 25 Nov in reply to Viktor Tachev Link to this post

    Hi Viktor Tachev,
    Actually i used auto generated columns in telerik radgrid, and the field for the column showing the Date is surely a DateTime.

    it sorts with respect to day, not w.r.t year, i want to sort w.r.t year.

    in above post i showed my radgrid code and i am going to attache a screen shot of grid showing sorted data of Date Field

  9. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 30 Nov Link to this post

    Hello Shafqat,

    I created a sample project with RadGrid that has autogenerated columns. The dates in the sample are sorted as expected on my end. Please give the sample a try and let me know how it works for you.

    I would appreciate it if you can modify the sample in a way that the behavior you are seeing is replicated and send it back. This way we can examine the issue and look for its cause.

    Regards,
    Viktor Tachev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  10. Shafqat
    Shafqat avatar
    3 posts
    Member since:
    Nov 2016

    Posted 30 Nov in reply to Viktor Tachev Link to this post

    Hi Viktor Tachev

    Thank you so much. my issue is fixed now, actually i was converting the date column to Varchar through SQL Function Convert(varchar(10),startDate,101) before Binding to Grid, that's why sorting was not working correctly. Now i am converting date column to Date with SQL Function CAST(DoBirth AS DATE) before binding to Grid.

    Once again Thank you so much for responding me.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017