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

Sorting groups by week number

14 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Iron
Kjell asked on 02 Apr 2014, 07:38 AM
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>

14 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Apr 2014, 07:54 AM
Hello,

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

Thanks,
Jayesh Goyani
0
Kjell
Top achievements
Rank 1
Iron
answered on 02 Apr 2014, 08:18 AM
field weeknumber have datatyp int
field datum have datatyp smalldatetime
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Apr 2014, 01:13 PM
Hello,

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

Thanks,
Jayesh Goyani
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Apr 2014, 04:06 AM
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
0
Kjell
Top achievements
Rank 1
Iron
answered on 04 Apr 2014, 08:23 AM
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>
0
Radoslav
Telerik team
answered on 08 Apr 2014, 11:24 AM
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.

 
0
Kjell
Top achievements
Rank 1
Iron
answered on 08 Apr 2014, 12:07 PM
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....

0
Kjell
Top achievements
Rank 1
Iron
answered on 08 Apr 2014, 12:08 PM
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....
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Apr 2014, 03:56 PM
Hello,

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

Thanks,
Jayesh Goyani
0
Kjell
Top achievements
Rank 1
Iron
answered on 10 Apr 2014, 06:44 AM
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 ..
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Apr 2014, 06:31 AM
Hello,

Can you please reproduce same issue in above demo?

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

Thanks,
Jayesh Goyani
0
Radoslav
Telerik team
answered on 14 Apr 2014, 10:33 AM
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.

 
0
Kjell
Top achievements
Rank 1
Iron
answered on 14 Apr 2014, 11:17 AM
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.
0
Radoslav
Telerik team
answered on 17 Apr 2014, 05:51 AM
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.

 
Tags
Grid
Asked by
Kjell
Top achievements
Rank 1
Iron
Answers by
Jayesh Goyani
Top achievements
Rank 2
Kjell
Top achievements
Rank 1
Iron
Radoslav
Telerik team
Share this question
or