WinForms Pivot Grid

Transform Tables into Slice-and-Dice Reports

 

As you browse these web pages and begin using the XtraPivotGrid within your applications, you will discover that when it comes to ease-of-use and flexibility, the XtraPivotGrid has no equal in the marketplace. Fact is that when it comes to data analysis and data mining, the XtraPivotGrid is the only product that empowers your end-users to solve their business needs without being forced to use cumbersome and overly complex reporting solutions.

To demonstrate just how easy it is to implement the XtraPivotGrid, we'll quickly describe the benefits of a pivot layout, guide you through the basics of creating pivot reports and describe just a few of the end-user options available out-of-the-box.

This page is broken down into the following main sections:

Transform Plain-Table Data into a Pivot Report

For demonstration purposes, let's consider a car sales database with the following structure:

A simple relational database structure

You can easily construct a query that will merge the information in all the tables into a single record set. If each record in the Orders table represents a single-car purchase, the total number of fields in the query's results will match the total number of cars sold. Summing by the Price field will generate sales totals.

Plain-table data queried from the database

Based on the data contained in these tables, let's assume your customer requests that you display on-screen and in printed form the total number of cars sold on any given day, by individual model - and how sales of these models have changed over time. To solve this business requirement and demonstrate the power of the XtraPivotGrid, we'll go ahead and bind the PivotGrid to the record set and create the fields which correspond to the underlying data source.

Bind Developer Express WinForms Pivot Grid component to plain-table data (query result)

To construct the appropriate report layout, you simply need to drag fields to the correct region. As such, if you need to see a cross-report of sales by dates and models, simply drag the OrderDate and Model headers to the Column and Row areas. To display the sum of sales for each date and model intersection, drag the Price header to the data area. The image below shows the resulting report. Instead of a hard to read table of data with numerous records that have to be scrolled vertically and then analyzed (a laborious process to say the least), your customer instead has a fully summarized and compact report at his fingertips.

The first pivot report. Each data cell in a pivot grid is a summary calculated against the appropriate cells from the bound table.

End-users can freely drag field headers in the same manner as you do at design time. Just a few drag and drop operations can entirely change the report's layout. This allows end-users to analyze the source data in the way they want to, without you having to redo a single thing. Below are a few examples that have been generated by simply dragging the field headers between areas.

Use Multiple Data Fields in a Report

The previous example showed an extremely simple report with just a data field. This means that there is a single cell at each column/row intersection. But the XtraPivotGrid lets you create reports which have an unlimited number of data fields. In addition to that, you and end-users have additional options for customizing the control's layout.

Let's add one more field to the control to display the number of cars sold. The only field in the previous example (Price) used the default summary type for numeric columns - sum. For the newly added field, you need to change the summary type to count. There are 9 different built-in summary types available within the XtraPivotGrid.

Specifying an aggregate function type for pivot report's data cells

Note: the XtraPivotGrid does not limit you with these predefined summary types. You can implement a custom aggregate function by writing a CustomSummary event handler.

Now, when multiple fields are in the report, you can enable the Data header. Like any other header, you or end-users can drag it to different locations to fine-tune your report. This header lets you control which data to display first, whether to arrange data fields horizontally or vertically, etc. The content, size and availability of the Data header are controlled via the control's OptionsDataField property.

Two data fields in one report - two cells per each row and column intersection

The following screenshots offer a glimpse into additional layouts that are just a drag and drop away from your users.

Adopt Any Data Using Manually Calculated Fields

Consider a more general case when the Orders table contains one more field - UnitsOnOrder. In this instance, the sales volume for each record is Price multiplied by UnitsOnOrder.

Updated structure of the source relational database

To display the sales volume in the XtraPivotGrid, you can easily add a manually calculated field which will hold Price multiplied by UnitsOnOrder. To accomplish this task, you need to carry out three simple steps. Add a new field, set its UnboundType property to Decimal and write a two-line handler for the CustomUnboundFieldData event.

C#
VB
private void pivotGridControl1_CustomUnboundFieldData(object sender,
    CustomFieldDataEventArgs e) {
   if(e.Field.Name == "fieldSales") {
      e.Value = (decimal)e.GetListSourceColumnValue("Price") *
         (int)e.GetListSourceColumnValue("UnitsOnOrder");
   }
}

Now you can create a new report that will match the updated database structure. Simply drag the newly created Sales field to the data area and fine-tune your report by moving other headers to the desired locations. The following image shows a sample.

Pivot grid's cell values (summaries) can be calculated using values from more than one data source field

Show Trends Using the Built-in Summary Variation Feature

If the main aim of end-users is to analyze trends - see how values are changing with time or depending on other values - you will be glad to know that the XtraPivotGrid offers you a built-in solution for this objective. You can trigger a single property to force cells to display differences rather than actual values. And there are two difference display modes available - absolute or percent.

Take a look at the next image for an example. Initially, there are two fields in the data area. They are bound to the same data field and thus display the same values. After you change one field's SummaryVariation property to Absolute, this field lets you see how sales were changing with time. Each cell displays the difference between its actual value and the value in the preceeding cell.

Use relative value display - show how data changes with time to better visualize trends

In the screenshot above, you see the variation displayed by dates. The obvious question is how can one change variation direction to display trends by trademarks. This is possible by means of the Data header discussed earlier. End-users can drag it to the column area to display left-to-right trends or to the row area to display top-to-bottom trends. You can control this programmatically using the OptionsDataField.Area property even if the Data header is invisible.

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.