Sorting groups by week number

16 posts, 0 answers
  1. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 02 Apr 2014 Link to this post

    Want to sort my group by week number based on the date field.
    Trying to convert my old grid (attached old_grid.gif) to Telerik: RadGrid (attached telrik_grid.gif) but the grouping gets sorted recipe from 1-52. I want to get the grouping based on the date field, in this case, week 8 (see attached old_grid.gif)

    Attached old_grid.gif is correct grouped........

    The asp:SqlDataSource:
    SelectCommand="select * from dogtraining where fidnr = @fidnr Order By datum DESC"

    The GroupByExpressions:​
    <GroupByExpressions>
        <telerik:GridGroupByExpression>
            <SelectFields>
                <telerik:GridGroupByField FieldName="weeknumber" FieldAlias="Vecka" />
            </SelectFields>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="weeknumber" />
            </GroupByFields>
        </telerik:GridGroupByExpression>
    </GroupByExpressions>
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 02 Apr 2014 in reply to Kjell Link to this post

    Hello,

    Please convert "weeknumber" field in to INT or DECIMAL.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 02 Apr 2014 in reply to Jayesh Goyani Link to this post

    field weeknumber have datatyp int
    field datum have datatyp smalldatetime
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 02 Apr 2014 Link to this post

    Hello,

    Once againg i will try to reproduce this issue with your code and get back to you.

    Thanks,
    Jayesh Goyani
  6. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Apr 2014 in reply to Jayesh Goyani Link to this post

    Hello,

    Can you please provide your code and information of telerik DLL version?

    I have alraedy tried twice but not able to reproduce this issue.

    Thanks,
    Jayesh Goyani
  7. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 04 Apr 2014 in reply to Jayesh Goyani Link to this post

    The version is: 2014.1.225.40

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        Dim id As FormsIdentity = TryCast(User.Identity, FormsIdentity)
        Dim ticket As FormsAuthenticationTicket = id.Ticket
     
        Dim userDataString As String = ticket.UserData
        Dim userDataPieces As String() = userDataString.Split(",".ToCharArray())
     
        Dim UserId As Integer = userDataPieces(0)
     
        sdsMedlem.SelectParameters("fidnr").DefaultValue = UserId
     
    End Sub




      <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
      <telerik:RadSkinManager ID="RadSkinManager1" Skin="Office2007" runat="server" />
     
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
         
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
     
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    function RowDblClick(sender, eventArgs) {
                        window.radopen("visa_trainingdog.aspx?id=" + eventArgs.getDataKeyValue("id"), "RadWindow1");
                    }
                </script>
            </telerik:RadCodeBlock>
     
    <telerik:RadGrid ID="RadGrid1" runat="server"
    AllowSorting="true"
    AllowPaging="true"
    CellSpacing="0"
    Culture="sv"
    DataSourceID="sdsMedlem"
    EnableLinqExpressions="false"
    GridLines="None"
    PageSize="40"
    Width="100%">
      <MasterTableView AutoGenerateColumns="False" DataKeyNames="id" ClientDataKeyNames="id" TableLayout="Fixed">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="weeknumber" FieldAlias="Vecka" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="weeknumber" SortOrder="None" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
          <PagerStyle Mode="Slider" PagerTextFormat="{4} Sida {0} av {1} ({5} träningspass)" />
          <Columns>
              <telerik:GridBoundColumn DataField="id" Display="false" />
              <telerik:GridBoundColumn DataField="datum" DataFormatString="{0:yyyy-MM-dd}" DataType="System.DateTime" HeaderText="Datum" HeaderStyle-Width="80px" />                                 
              <telerik:GridBoundColumn DataField="weeknumber" HeaderText="Vecka" DataType="System.Int32" HeaderStyle-Width="70px" />
              <telerik:GridBoundColumn DataField="aktivitet" HeaderText="Aktivitet" HeaderStyle-Width="70px" />
              <telerik:GridBoundColumn DataField="distans" HeaderText="Distans" HeaderStyle-Width="70px" />
              <telerik:GridBoundColumn DataField="exercise" HeaderText="Träningstid" DataType="System.DateTime" HeaderStyle-Width="80px" />
              <telerik:GridBoundColumn DataField="plats" HeaderText="Plats"  />
              <telerik:GridTemplateColumn HeaderButtonType="TextButton" HeaderStyle-Width="30px">
                  <ItemTemplate>
                    <asp:LinkButton ID="lbVisa" ImageAlign="AbsMiddle" Text='<img src="../../../picture/mini/edit.gif" width="18" height="18" border="0" />' Tooltip="Uppdatera träningspass" CommandArgument='<%# Container.DataItem("id") %>' OnClick="Visa" PostBackUrl="~/medlemsidor/minsida/trainingdog/edittrainingdog.aspx" runat="server" />
                  </ItemTemplate>
              </telerik:GridTemplateColumn>
          </Columns>
      </MasterTableView>
        <ClientSettings EnableRowHoverStyle="True" AllowColumnsReorder="true">
        <Resizing AllowColumnResize="true" />
        <ClientEvents OnRowDblClick="RowDblClick" />
        <ClientMessages PagerTooltipFormatString="" />
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="490px" />
        </ClientSettings>
    </telerik:RadGrid>
     
          <telerik:RadWindowManager ID="RadWindowManager1" Behaviors="Close" RestrictionZoneID="zoneID1" runat="server">
              <Windows>
                  <telerik:RadWindow ID="RadWindow1" Width="602px" Height="400px" Top="118px" Left="-6" EnableShadow="true"
                   ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" VisibleStatusbar="false" runat="server">
                  </telerik:RadWindow>         
              </Windows>
          </telerik:RadWindowManager>
     
         <asp:SqlDataSource ID="sdsMedlem" runat="server" ConnectionString="<%$ ConnectionStrings:MyInlogg %>" ProviderName="System.Data.SqlClient" SelectCommand="select * from dogtraining where fidnr = @fidnr Order By datum DESC">
          <SelectParameters>
              <asp:Parameter Name="fidnr" />
          </SelectParameters>
        </asp:SqlDataSource>
  8. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 08 Apr 2014 Link to this post

    Hello Kjell,

    Thank you for contacting us.

    Could you please elaborate a bit more on your scenario? What do you try to achieve? From the provided screenshots I saw that the RadGrid groups correctly the data. Also I am sending you a simple example which demonstrates that the grid correctly groups the data. Also if you want to sort the groups descending you need to set the GroupByFields.GridGroupByField.SortOrder to Descending:
    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldName="weeknumber" FieldAlias="Vecka" />
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="weeknumber" SortOrder="Descending" />
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
    The example which I am sending you demonstrates that. Please check it out and let me know if it helps you.

    Looking forward for your reply.

    Regards,
    Radoslav
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 08 Apr 2014 in reply to Radoslav Link to this post

    I want the grid sorted by SqlDataSource Order By datum DESC
    Then GroupBy the weeknumber
    Like this: http://www.telerik.com/clientsfiles/95176854-878b-47c7-9416-5cafa7225281_old_grid.gif?sfvrsn=0
    Same config of grid, but different grid....

  10. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 08 Apr 2014 in reply to Radoslav Link to this post

    I want the grid sorted by SqlDataSource Order By datum DESC
    Then GroupBy the weeknumber
    Like this: http://www.telerik.com/clientsfiles/95176854-878b-47c7-9416-5cafa7225281_old_grid.gif?sfvrsn=0
    Same config of grid, but different grid....
  11. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 08 Apr 2014 Link to this post

    Hello,

    Please download demo from below link.
    http://jmp.sh/bkT924u

    Thanks,
    Jayesh Goyani
  12. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 10 Apr 2014 in reply to Jayesh Goyani Link to this post

    Unfortunately it made no difference to convert the column to varchar.
    Have tried all variants now and most likely the problem lies in the function ConstantRecords, that were in my old grid component from componentart.
    I used GroupingMode = "ConstantRecords"  which the same function is not available in Telerik: RadGrid ..
  13. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 14 Apr 2014 in reply to Kjell Link to this post

    Hello,

    Can you please reproduce same issue in above demo?

    So, it is easy to us, to resolved your issue.

    Thanks,
    Jayesh Goyani
  14. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 14 Apr 2014 Link to this post

    Hello Kjell,

    I am not sure I completely understand your requirements. Could you please elaborate a bit more on your scenario?
    Also do you check the example which I’ve sent you? Does it cover your scenario and requirements?
    Additionally please note that the RadGrid groups data internally and you can sort the grid only by the field which is used for grouping (into my example the weeknumber field). Grouping by one field and sorting by another is not supported scenario because the groups will be invalid. If you want to sort grouped grid by different field the data into the groups will be sorted, but the groups will stay in the same order. You can inspect this behavior in the following demo:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/grouping/grouping/defaultcs.aspx
    If you try to sort a column (for example From column), the data in all groups will be sorted, however the groups sequence will not be changed. If you want to change the group order you need to press group item sort icon or add SortOrder to into the GroupByFields.GridGroupByField like in my example.

    Looking forward for your reply.

    Regards,
    Radoslav
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  15. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 14 Apr 2014 Link to this post

    I dont know how I can explain better.
    I want the grid sorted by the date field (datum) from my Select Command "Order By datum DESC", then group the grid by week number.
    With telriks grid sorted by grouping the grid which in this case is the week number (1-52)
    Look at the pictures I attached, old_grid.gif sorting and grouping is what i want telriks grid should do.
  16. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 14 Apr 2014 in reply to Kjell Link to this post

    Hello,

    Can you please provide your project/demo project (In which this issue is exists)?

    So, we all are try to resolved your issue.

    Thanks,
    Jayesh Goyani
  17. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 17 Apr 2014 Link to this post

    Hi Kjell,

    Like I said into my previous reply the RadGrid does not support sorting by one field and grouping by another field. If this can be achieved the sorting of the first field will be broken, because grouping by second field will rearrange the first field sorting.
    Additionally into the example which I sent you with my previous reply the week numbers are ordered descending. Is this your requirement? Into the mentioned old_grid.gif image the week numbers are ordered descending as into my example.

    Looking forward for your reply.

    Regards,
    Radoslav
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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