Creating Fields and Binding Them to Data Fields
- 3 minutes to read
To create a report in Pivot Grid, pivot grid fields should be created and positioned within appropriate areas:
- Create a PivotGridField object and add it to the PivotGridControl.Fields collection;
- Locate the field within the required area. To do this, use the field's PivotGridField.Area and PivotGridField.AreaIndex properties. A field can be positioned within one of four areas: Data, Row, Column or Filter Header Area.
The field's function is determined by the area in which it is displayed:
- Position a field within the Column Header Area to list its values along the grid's top edge. The field's values will represent column headers.
- Position a field within the Row Header Area to list its values along the grid's left edge. The field's values will represent row headers.
- Position a field within the Data Header Area to calculate summaries against this field.
- Position a field within the Filter Header Area to make this field available for data filtering or further customizations (e.g. it can be dragged to a different area later on).
#Binding Basics
DXPivotGrid supports bound and unbound fields. A bound field retrieves data from a field in a pivot grid's data source. An unbound field is not associated with a data source and should be populated with data manually. To learn more on unbound fields, see Unbound Fields.
To bind a pivot grid field to a data source field, use the PivotGridField.FieldName property. This property provides the name of the data field bound to the pivot grid field. The PivotGridField.UnboundType property must be set to FieldUnboundColumnType.Bound.
To learn more, see Binding to Data Overview and Binding to an OLAP Server.
#Example
The following example demonstrates how to bind a pivot grid to an embedded XML file.
In this example, an XML file that contains data from the Northwind database is embedded into a Silverlight application. The System.Xml.Serialization.XmlSerializer object is used to parse this file and create a collection of data items. Then, the pivot grid is bound to data by assigning this collection to the PivotGridControl.DataSource property. In the markup, four pivot grid fields are created, mapped to data fields using the PivotGridField.FieldName property and put into the appropriate pivot grid areas via the PivotGridField.Area property.
Classes that define a data item and a data item collection are declared in a separate file. The name and member set of the data item class match the declaration of the corresponding data element in the XML schema.
To learn how to create this sample step-by-step, see Lesson 2 - Binding a Pivot Grid to an Embedded XML File.