[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Collapse]Pivot Grid
   [Expand]Getting Started
   [Expand]Fundamentals
   [Collapse]Binding to Data
     Binding to Data Overview
    [Expand]Items Source Configuration Wizard
    [Expand]OLAP Data Source
    [Expand]Database Server Mode
     Unbound Fields
     Local Data Stores
     Asynchronous Mode
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Expand]Layout
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Appearance
   [Expand]MVVM Enhancements
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Unbound Fields

The Pivot Grid supports bound and unbound fields:

  • Bound fields retrieve data from the pivot grid's underlying data source.
  • Unbound fields get data by evaluating an expression or handling an event. U You can use unbound fields to construct and display user-friendly values in field headers:

You can sort, group and filter unbound fields in the same manner as bound fields.

Note

Unbound fields cannot be used in OLAP mode.

Tip

If you have the Interactive Demos installed, review the Unbound Expressions demo.

This topic consists of the following sections:

Expanded Create an Unbound Field in Visual Studio Designer

Follow the steps below to create a new unbound field in the PivotGrid control.

  1. Click the Fields (Collection) ellipsis button in the PivotGridControl Properties window. In the invoked PivotGridField Collection Editor: Fields window click Add to add a new field.

  2. Specify the PivotGridField.UnboundFieldName property value. Make sure that it does not match any existing PivotGridField.Name or PivotGridField.FieldName values.
  3. Change the value of the field's PivotGridField.UnboundType property from Bound to a value type from the drop-down list.

  4. Specify an expression to fill the field with data. Click the ellipsis button next to the PivotGridField.UnboundExpression property and enter the expression in the invoked Expression Editor:

    Refer to the Pivot Grid Expression Syntax document for more information about the expression operators and functions.

    Tip

    You can handle the CustomUnboundFieldData event to supply data to unbound fields.

Expanded Create an Unbound Field in XAML

This example creates a field with full names generated from the first and last names stored in the underlying data source. The code snippet below demonstrates how to create a field in markup:

The UnboundFieldName should be unique across field names. Use the PivotGridField.UnboundExpression property to populate a field with data. Refer to the Pivot Grid Expression Syntax topic for more information about expressions.

Expanded Create an Unbound Field in Code

This example creates a field with full names generated from the first and last names stored in the underlying data source. The code snippet below demonstrates how to create a field in code:

The UnboundFieldName should be unique across field names. Use the PivotGridField.UnboundExpression property to populate a field with data. Refer to the Pivot Grid Expression Syntax topic for more information on expressions.

Tip

To refer to a Pivot Grid field within an expression, use the name obtained from the PivotGridField.ExpressionFieldName property.

Expanded Provide Data Using the Event

You can handle the PivotGridControl.CustomUnboundFieldData event for complex calculations that cannot be performed using expressions. The PivotGrid control fires this event for each unbound field and row in the data source.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E2122.

This example demonstrates how to add an unbound field to the PivotGridControl, to show the total sum of an order.

The PivotGridControl is bound to the Order Details data table (from the nwind sample database), which contains UnitPrice, Quantity and Discount fields. The total sum is calculated as follows: UnitPrice*Quantity*(1-Discount).

To solve this task, create a PivotGrid's field and set its PivotGridField.UnboundType property to FieldUnboundColumnType.Decimal. Then, handle the PivotGridControl.CustomUnboundFieldData event and populate the field with data.

Note

The PivotGridControl.CustomUnboundFieldData event is not supported in server and OLAP modes.

Expanded Change Unbound Expression Mode

The PivotGridField.UnboundExpressionMode property allows you to change the unbound field expression's calculation mode. The default mode is that an expression is calculated against each data source record, and resulting values are summarized. Another option is calculation on a summary (visualization) level, when an expression uses the summarized (displayed in a pivot table) values. A sort of summary calculations involves a set of summary functions (such as Sum, Avg, etc.) to summarize data source records. The following table lists the available modes:

Unbound Expression Mode Description
FieldUnboundExpressionMode.DataSource The FieldUnboundExpressionMode.DataSource mode allows you to compute unbound field values on a data source level. In the image below, the ExtendedPrice field is calculated based on underlying UnitPrice and Quantity values.

After you add the created unbound field to the Data Header area, the Pivot Grid uses the summary function to summarize its data.

In this case, unbound field values are calculated before summarization.

FieldUnboundExpressionMode.UseSummaryValues The FieldUnboundExpressionMode.UseSummaryValues mode enables you to compute unbound field values on a visualization (or summary) level. In this case, the Pivot Grid uses the displayed data to compute unbound field values.

To calculate a margin for a product, you have to divide its Profit value by its ExtendedPrice value.

In this mode, an expression uses summaries.

Note

Hidden data source fields or fields located in the Filter Header area are not summarized and cannot participate in the calculation. To overcome this restriction, you can use the FieldUnboundExpressionMode.UseAggregateFunctions mode. This mode allows you to include aggregate functions in an expression and use them on a data source level.

FieldUnboundExpressionMode.UseAggregateFunctions The FieldUnboundExpressionMode.UseAggregateFunctions mode introduces a specified set of aggregate functions (Sum, Min, Max, etc.). These functions can be used to perform summary calculations on a data source level.

The following example illustrates the margin calculation. The sum of Profit values is divided by the sum of ExtendedPrice values.

Note

If you enable the FieldUnboundExpressionMode.UseAggregateFunctions mode, the Aggregate function group appears in the Expression Editor available to end-users.

FieldUnboundExpressionMode.Default The UnboundExpressionMode.Default setting indicates that the PivotGridOptionsData.DataFieldUnboundExpressionMode property value specifies the calculation mode. This setting allows you use the Pivot Grid's global option to control how unbound fields are calculated.

Expanded Enable End-Users to Edit Expressions

End-users can use the Expression Editorto edit unbound field expressions. To make this editor available to users, set the PivotGridFieldOptionsEx.ShowUnboundExpressionMenu property to true. This adds the Expression Editor... command to a field's context menu.

In code, use the PivotGridControl.ShowUnboundExpressionEditor method to invoke the editor.

Use the PivotGridOptionsBehavior.ExpressionEditorMode property to specify the Expression Editor’s version.

Expanded Enable End-Users to Change Expressions

You can supply end-users with the capability to change specific unbound field expressions using the Expression Editor. To do this, set the PivotGridField.AllowUnboundExpressionEditor property to true. This adds the Expression Editor... command to this field's context menu.

You can also call the PivotGridControl.ShowUnboundExpressionEditor method to invoke the Expression Editor.

Expanded Member Table

The table below lists members related to creating and using unbound fields:

Property

Description

PivotGridField.UnboundType Gets or sets the data type and binding mode of the field. This is a dependency property.
PivotGridField.UnboundFieldName Gets or sets the name of a column in a summary data source that corresponds to the current unbound field. This is a dependency property.
PivotGridField.ExpressionFieldName Gets the name by which the field is referred to in unbound expressions.
PivotGridField.UnboundExpressionMode Gets or sets how the unbound expression for the specified data field is calculated.
PivotGridControl.DataFieldUnboundExpressionMode Gets or sets whether unbound expressions for data fields are calculated based on the data source records, or summary values. This is a dependency property.
PivotGridField.AllowUnboundExpressionEditor Gets or sets whether end-users can invoke the Expression Editor for the field. This is a dependency property.
PivotGridField.ShowInExpressionEditor Gets or sets whether the current field is available in the field list in the Expression Editor.

Event

Description

PivotGridControl.CustomUnboundFieldData Enables providing data to unbound fields.
PivotGridControl.FieldUnboundExpressionChanged Fires after the PivotGridField.UnboundExpression property's value has been changed.
PivotGridControl.UnboundExpressionEditorCreated Fires after an Expression Editor has been created for an unbound field.

Method

Description

PivotGridControl.ShowUnboundExpressionEditor Invokes the Expression Editor used to create expressions for unbound fields.

Is this topic helpful?​​​​​​​