Default Datetime field sorting in Descending order is not working in Radgrid

9 posts, 0 answers
  1. Mandy
    Mandy avatar
    33 posts
    Member since:
    Mar 2010

    Posted 18 Aug 2010 Link to this post

    i am trying with both gridboundColumn and with gridDatetime column but its is not working for any of ane.below is my code for sorting .
    Please let me know if i had done any mistake in this ASAP.


    <telerik:RadGrid ID="gvMessages" runat="server" AllowSorting="true" ShowGroupPanel="true"
                                                            PageSize="20" AllowPaging="True" AutoGenerateColumns="False" GridLines="Horizontal"
                                                            OnItemDataBound="gvMessages_ItemDataBound" OnNeedDataSource="gvMessages_NeedDataSource"
                                                            OnGroupsChanging="gvMessages_GroupsChanging" OnItemCreated="gvMessages_ItemCreated"
                                                            OnItemCommand="gvMessages_ItemCommand" AllowMultiRowSelection="true" OnRowDrop="gvMessages_RowDrop">
                                                            <HeaderContextMenu EnableAutoScroll="True" />
                                                            <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="MessageID,PhaseID"
                                                                ClientDataKeyNames="MessageID">
                                                                <SortExpressions>
                                                                    <telerik:GridSortExpression FieldName="DateCreated" SortOrder="Descending" />
                                                                    <telerik:GridSortExpression FieldName="DateCreated" SortOrder="Descending" />
                                                                </SortExpressions>
                                                                <Columns>
                                                                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="MessageID" DataField="MessageId">
                                                                        <HeaderStyle Width="20px" />
                                                                        <ItemTemplate>
                                                                            <asp:Image ID="imgFiles" runat="server" ImageUrl="~/Images/attachment-icon.png" Height="18px"
                                                                                Width="17px" />
                                                                        </ItemTemplate>
                                                                    </telerik:GridTemplateColumn>
                                                                    <telerik:GridBoundColumn SortExpression="Email" AutoPostBackOnFilter="true" HeaderText="From"
                                                                        HeaderButtonType="TextButton" DataField="Email" UniqueName="Email">
                                                                        <HeaderStyle Width="150px" />
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridBoundColumn SortExpression="MessageSubject" AutoPostBackOnFilter="true"
                                                                        HeaderText="Subject" HeaderButtonType="TextButton" DataField="MessageSubject"
                                                                        UniqueName="MessageSubject">
                                                                        <HeaderStyle Width="200px" />
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridBoundColumn DataFormatString="{0:MM/dd/yyyy 00:00:00}" SortExpression="DateCreated"
                                                                        AutoPostBackOnFilter="true"  AllowSorting=true DataType="System.TimeSpan" HeaderText="Date" HeaderButtonType="TextButton"
                                                                        DataField="DateCreated" UniqueName="DateCreated">
                                                                        <HeaderStyle Width="200px" />
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridBoundColumn SortExpression="SenderName" AutoPostBackOnFilter="true"
                                                                        HeaderText="Created By" HeaderButtonType="TextButton" DataField="SenderName"
                                                                        UniqueName="SenderName">
                                                                        <HeaderStyle Width="200px" />
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Phase Name" UniqueName="PhaseID"
                                                                        DataField="PhaseID">
                                                                        <HeaderStyle Width="200px" />
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblPhase" runat="server" Text='<%#Eval("TagName").ToString() %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                    </telerik:GridTemplateColumn>
                                                                </Columns>
                                                            </MasterTableView>
                                                            <ClientSettings>
                                                                <ClientEvents OnRowContextMenu="RowContextMenu1"></ClientEvents>
                                                                <Selecting AllowRowSelect="true" />
                                                            </ClientSettings>
                                                            <ClientSettings AllowDragToGroup="True" AllowRowsDragDrop="true" ReorderColumnsOnClient="True"
                                                                AllowColumnHide="True" AllowRowHide="True" AllowColumnsReorder="True">
                                                                <Resizing EnableRealTimeResize="True" ResizeGridOnColumnResize="True" AllowColumnResize="True"
                                                                    ClipCellContentOnResize="False"></Resizing>
                                                                <ClientEvents OnRowDblClick="ShowMessage" />
                                                                <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
                                                                <Selecting AllowRowSelect="True" />
                                                                <ClientEvents OnRowDropping="onRowDropping" />
                                                            </ClientSettings>
                                                            <GroupingSettings CaseSensitive="false" />
                                                        </telerik:RadGrid>

    Thanks.
  2. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 20 Aug 2010 Link to this post

    Hello Mandeep,

    Could you specify what exactly do you mean by "not working" - does it throw an error or it does not sort properly?

    Also, could you please share what are the results if you:
    -Remove the initial sort and try to sort the column on header click? Does it sort normally this time?
    -If not, what happens if you convert the TimeSpan data to string? I know that it will now be sorting alphabetically but does it sort without problems?

    The answers to these questions will help us narrow down the set of possible reasons for the erroneous behavior.

    All the best,
    Tsvetina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shuaib
    Shuaib avatar
    2 posts
    Member since:
    Dec 2011

    Posted 27 Dec 2011 Link to this post

    Hi

    I'm working on a similar issue.
    I want to get my radgrid sorted on the 'Date' field in a descending order when the grid loads for the first time.
    The grid is bound to a webmethod.
    Can you guide me?

    Thanks,
    Shuaib
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Dec 2011 Link to this post

    Hello,

    Try the following code.
    C#:
    protected void Page_Load(object sender, EventArgs e)
       {
         GridSortExpression expression = new GridSortExpression();
         expression.FieldName = "BirthDate";
         expression.SortOrder = GridSortOrder.Descending;
         grid1.MasterTableView.SortExpressions.AddSortExpression(expression);
         grid1.MasterTableView.Rebind();
       }

    -Shinu.
  6. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 27 Dec 2011 Link to this post

    Hi Shuaib,

    You can achieve this declaratively, for example:
    <MasterTableView>
         <SortExpressions>
               <telerik:GridSortExpression FieldName="OrderDate" SortOrder="Descending" />
         </SortExpressions>
    </MasterTableView>

    You can also add it programmatically, similarly to what Shinu showed but without the Rebind() on Page_Load, as this is not recommended practice.

    More information is available here.

    Regards,
    Tsvetina
    the Telerik team
    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 their blog feed now
  7. Shuaib
    Shuaib avatar
    2 posts
    Member since:
    Dec 2011

    Posted 28 Dec 2011 Link to this post

    Hi Tsvetina

    Thanks for your reply.
    But I need to click the header for the grid to get sorted when I add a sort expression that way.
    I want it to get sorted the first time it loads and shows up instead of clicking it to sort.

    Thanks,
    Shuaib
  8. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 29 Dec 2011 Link to this post

    Hi Shuaib,

    When using Shinu's code on initial Page_Load, the user does not need to do anything to get the sorting applied. You can see this in the following demo:
    http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultcs.aspx

    Greetings,
    Tsvetina
    the Telerik team
    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 their blog feed now
  9. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 17 Jan 2013 Link to this post

    Hi

    My RadGrid sorting does not work properly. I figure out that why its not working properly. I need its solution. Let me explain.

     public partial class TestPage: ParentClass  // System.Web.UI.Page
     {
     }

    I inherit My ParentClass instead of System.Web.UI.Page. So RadGrid not working properly. I have some session mgt in ParentClass.
    and My ParentClass is inherit from System.Web.UI.Page. But when i click on RadGrid sorting its does not properly. It sort only one time and some time i click on one column it sort other column.

    Can you have any solution that why its happening?

    If i did not inherit it from ParentClass and inherit it from System.Web.UI.Page . its work great.
    Thanks,
    Muhammad Waseem
    the Telerik team
  10. Mike
    Mike avatar
    1 posts
    Member since:
    Jan 2013

    Posted 22 Jan 2013 Link to this post

    Shinu - I know this is an old post but wanted to compliment you on your default sort code in Page_Load() - it works great!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017