Group and Sort the Report Data
- 4 minutes to read
This document describes a general technique to group and sort data in the report. For special cases, refer to the other help topics in this section.
Note that you can specify group and sort settings only for the report bound to the data source.
Use the Group and Sort Panel
Start with a new blank report and bind it to the
Products table of the sample Northwind database:
You should specify both DataSource and DataMember property values.
Do the following to group and sort the report data:
Click Group and Sort in the Visual Studio XtraReports menu to invoke the Group and Sort panel.
Click Add a Group and select the data field by which you wish to group the data:
This action creates an empty group header, a GroupField that relates to the selected data field, and adds the group field to the GroupHeaderBand.GroupFields collection.
Open the group header’s smart tag and click the ellipsis next to the GroupFields property editor to invoke the Group Field Collection Editor:
You can use the Group Field Collection Editor to group data by multiple criteria. Click Add to create a new group field and specify its GroupField.FieldName property.
Use the arrow buttons to change the order in which these criteria are applied to the report data.
In the Group and Sort panel, you can specify how the groups are sorted (in ascending or descending order). Select None if your groups are already ordered in the data source, and you do not need to sort them in the report.
Select Show Footer to create an empty GroupFooterBand for this group.
When a report has multiple groups, you can click Move Up or Move Down to change group order:
Drag fields from the Field List and drop them onto the group header and detail bands to display field values in the report:
The resulting report looks as follows:
Group Fields vs Group Headers
You can add multiple group fields to a single header or create multiple group headers. The report layout is different in these situations, as shown in the following image:
|Single Group Header, multiple Group Fields||Muliple Group Headers, each with a single Group Field|
Specify Group Settings
You can use the smart tag to customize the group layout settings:
- GroupUnion property
- Allows you to keep content on the same page.
- KeepTogether property
- Allows you to print the group header/footer on the same page as the group content.
- RepeatEveryPage property
- Prints the group band on every page.
- Band.PageBreak property
- Starts a new page before or after a group.
Page Numbers in Groups
To display page numbers for individual groups, add the XRPageInfo control to the group header or footer and set its XRPageInfo.RunningBand property to the group header’s name:
Different groups should not appear on the same page for accurate page numbering. To meet this requirement, set the PageBreak property to AfterBand, or place the XRPageBreak control at the bottom of the band.
For more information, review the following help topic: Add Page Numbers.
Interactive Sort in Print Preview
You can allow end users to sort report data in Print Preview interactively. The user can click a designated element to change the sort order.
For more information, review the following help topic: Sort a Report in Print Preview.
Group Band Without Group Fields
You can add a group band to a report without adding group fields to the band’s collection. The RepeatEveryPage property specifies how the report displays the group band without group fields:
Group Band Visibility
The band is shown once at the report’s beginning/end.
The band is shown on each page at the beginning/end.