Back to Devexpress

Group and Sort the Report Data

xtrareports-1298-feature-guide-to-devexpress-reports-shape-report-data-group-and-sort-group-and-sort-a-reports-data.md

latest6.1 KB
Original Source

Group and Sort the Report Data

  • Feb 18, 2026
  • 4 minutes to read

This document describes a general technique to group and sort data in the report.

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:

  1. Click Group and Sort in the Visual Studio XtraReports menu to invoke the Group and Sort panel.

  2. Click Add a Group and select the data field by which you wish to group the data:

  3. Open the group header’s smart tag and click the ellipsis next to the GroupFields property editor to invoke the Group Field Collection Editor :

  4. 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.

  5. 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.

  6. Select Show Footer to create an empty GroupFooterBand for this group.

  7. When a report has multiple groups, you can click Move Up or Move Down to change group order:

  8. 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 FieldsMuliple Group Headers, each with a single Group Field

Specify Group Settings

You can use the smart tag to customize the group layout settings:

GroupUnion propertyAllows you to keep content on the same page.
KeepTogether propertyAllows you to print the group header/footer on the same page as the group content. RepeatEveryPage propertyPrints the group band on every page.
Band.PageBreak propertyStarts 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:

|

RepeatEveryPage

|

Group Band Visibility

| | --- | --- | |

false

|

The band is shown once at the report’s beginning/end.

| |

true

|

The band is shown on each page at the beginning/end.

|

See Also

Count the Number of Groups in a Report

Limit the Number of Records per Page