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

Grouping by month/year

1 Answer 282 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 18 Jan 2014, 05:57 PM
I have a Radgrid with a column "Period " which is shown as month/year (MMM/yyyy).
The column is bound to an sql table and the field is a datetime.

I have multiple entries for each period and I would like to group the rows by such filed in order to have all months/years collapsable and separated in the grid. How can I achieve that?
I have looked at various examples but I am not coming right. Your support is appreciated.
Thank you,
Felice

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" CellSpacing="0" Culture="it-IT" DataSourceID="SqlDataSource1" GridLines="None"  Height="560px" Skin="WebBlue">
                        <ExportSettings>
                           <Pdf  PaperSize="A4">
                           </Pdf>
                       </ExportSettings>
                       <ClientSettings>
                           <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                       </ClientSettings>
                       <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" PageSize="20">
                           <CommandItemSettings ShowExportToExcelButton="True" ShowExportToPdfButton="True" />
                           <RowIndicatorColumn Visible="False">
                           </RowIndicatorColumn>
                           <ExpandCollapseColumn Created="True">
                           </ExpandCollapseColumn>
                           <Columns>
                               <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="50px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Periodo" DataType="System.DateTime" FilterControlAltText="Filter Periodo column" HeaderText="Period" SortExpression="Periodo" UniqueName="Periodo" DataFormatString="{0:MMM/yyyy}">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="80px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Due" DataType="System.Int32" FilterControlAltText="Filter Due column" HeaderText="Due" SortExpression="Due" UniqueName="Due" DataFormatString="{0:R #.###,##}">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="80px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Paid" DataType="System.Int32" FilterControlAltText="Filter Paid column" HeaderText="Paid" SortExpression="Paid" UniqueName="Paid" DataFormatString="{0:R #.###,##}">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="80px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Data_pag" DataType="System.DateTime" FilterControlAltText="Filter Data_pag column" HeaderText="Payment date" SortExpression="Data_pag" UniqueName="Data_pag" DataFormatString="{0:dd/MM/yyyy}">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="100px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridCalculatedColumn  DataFields="Due, Paid" Expression="{0}-{1}" FilterControlAltText="Filter column column" UniqueName="Balance" DataFormatString="{0:R #.###,##}" HeaderText="Balance">
                                   <HeaderStyle Width="80px" />
                               </telerik:GridCalculatedColumn>
                               <telerik:GridBoundColumn DataField="Expenses" DataType="System.Int32" FilterControlAltText="Filter Expenses column" HeaderText="Expenses" SortExpression="Expenses" UniqueName="Expenses" DataFormatString="{0:R #.###,##}">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="80px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Ritardo" DataType="System.Int32" FilterControlAltText="Filter Ritardo column" HeaderText="Delay" ReadOnly="True" SortExpression="Ritardo" UniqueName="Ritardo">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                                   <HeaderStyle Width="50px" />
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="Notes" FilterControlAltText="Filter Notes column" HeaderText="Notes" SortExpression="Notes" UniqueName="Notes">
                                   <ColumnValidationSettings>
                                       <ModelErrorMessage Text="" />
                                   </ColumnValidationSettings>
                               </telerik:GridBoundColumn>
                           </Columns>
                       </MasterTableView>
                   </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Felice
Top achievements
Rank 1
answered on 18 Jan 2014, 08:08 PM
I found the solution. I hope this would be of help to other people  if needed.

</Columns>
<GroupByExpressions>
<telerik:GridGroupByExpression>
 <SelectFields>
<telerik:GridGroupByField FieldName="Periodo" FormatString="{0:MMM/yyyy}"/>
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldName="Periodo" FormatString="{0:MMM/yyyy}" SortOrder="Descending"/></GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
</MasterTableView>
</telerik:RadGrid>
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Felice
Top achievements
Rank 1
Share this question
or