Version

Binding xamPivotGrid to FlatDataSource

Topic Overview

Purpose

This topic explains how to use the FlatDataSource class for displaying IEnumerable data in the xamPivotGrid™.

Required background

The following table lists the topics required as a prerequisite to understanding this topic.

Topic Purpose

This section serves as an introduction to the xamPivotGrid control’s key features and functionalities. The topics listed here will give you a better idea of why you would want to use xamPivotGrid in your applications.

This topic demonstrates how to get started with the xamPivotGrid control by providing step-by-step procedure for adding this control to a WPF application.

This topic serves as an overview of the data sources supported by the xamPivotGrid control.

Using FlatDataSource

Introduction

Use the FlatDataSource to connect to data that uses the Online Transaction Processing (OLTP) model. In this case, the source can be a relational database, a Microsoft® Excel™ file, or an arbitrary two-dimensional data collection. The ItemsSource for the FlatDataSource can be any object that implements the IEnumerable interface (e.g. List, Collection, Queue, Stack etc.) An example of an object that meets the above criteria is the SalesDataSample object which you can download from the SalesDataSample resource and use in your project.

Note
Note:

The FlatDataSource is not suitable for Online Analytical Processing (OLAP) cubes. For these, use XmlaDataSource or data sources that derive from it.

Class Diagram

The following is a simplified diagram of how the xamPivotGrid works with flat data.

xamPivotGrid DataBinding Using FlatDataSource 1.png

Preview

The following screenshot is a preview of the final result.

xamPivotGrid DataBinding Using FlatDataSource 2.png

Requirements

To complete the procedure, you need the following:

  • A WPF application

  • The SalesDataSample class added to your application

  • Add the following NuGet package references to your application:

    • Infragistics.WPF.Controls.Grids.XamPivotGrid

    • Infragistics.WPF.Olap.FlatData

    For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.

Overview

This topic takes you step-by-step toward configuring the xamPivotGrid to work with a flat data source. The following is a conceptual overview of the process:

  1. Creating a FlatDataSource object.

  2. Setting the ItemsSource property of the FlatDataSource to an IEnumerable collection.

  3. Adding a xamPivotGrid and xamPivotDataSelector controls to your page.

  4. Setting the DataSource property of the grid and the data selector to the FlatDataSource.

Steps

The following steps conceptually explain how to set up a flat data source for the xamPivotGrid. You can find the complete code listing in the code example below.

  1. Create a FlatDataSource

Create an instance of the FlatDataSource class.

  1. Set the ItemsSource of the FlatDataSource property to an IEnumerable collection.

Create an instance of the SalesDataSample class and set it as the ItemsSource of the FlatDataSource. The SalesDataSample is basically an observable collection of Sale objects.

  1. Add a xamPivotGrid and xamPivotDataSelector controls to your page.

In order to display data in the xamPivotGrid you will need to choose hierarchies for the columns and rows and also to select at least one measure. The easiest way to do this is to add a xamPivotDataSelector control to your page.

  1. Set the DataSource property of the grid and the data selector to the FlatDataSource.

The last step is to set the FlatDataSource that you created as the DataSource of the xamPivotGrid and the xamPivotDataSelector.

Code Example: Using FlatDataSource with the xamPivotGrid

Description

The code below shows how to use an ObservableCollection (SalesDataSample) as a data source for the xamPivotGrid.

Code

In XAML:

xmlns:olap="http://schemas.infragistics.com/olap"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:models="clr-namespace:Infragistics.Samples.Data.Models"
...
<models:SalesDataSample x:Key="DataSample"/>
<olap:FlatDataSource x:Key="DataSource" ItemsSource="{StaticResource DataSample}" />
<!-- alternatively, -->
<olap:FlatDataSource>
    <olap:FlatDataSource.ConnectionSettings>
        <olap:FlatDataConnectionSettings ItemsSource="{StaticResource DataSample}" />
    </olap:FlatDataSource.ConnectionSettings>
</olap:FlatDataSource>
...
<ig:XamPivotGrid x:Name="PivotGrid" DataSource="{StaticResource DataSource}" />

In C#:

using Infragistics.Controls.Grids;       // xamPivotGrid control
using Infragistics.Olap.FlatData;        // FlatDataSource
using Infragistics.Samples.Data.Models;  // SalesDataSample
...
FlatDataSource DataSource = new FlatDataSource();
DataSource.ItemsSource = DataSample;
// alternatively,
SalesDataSample DataSample = new SalesDataSample();
FlatDataSource DataSource = new FlatDataSource();
FlatDataConnectionSettings DataConnectionSettings = new FlatDataConnectionSettings();
DataConnectionSettings.ItemsSource = DataSample;
DataSource.ConnectionSettings = DataConnectionSettings;
this.PivotGrid.DataSource = DataSource;

In Visual Basic:

Imports Infragistics.Controls.Grids       ' xamPivotGrid control
Imports Infragistics.Olap.FlatData        ' FlatDataSource
Imports Infragistics.Samples.Data.Models  ' SalesDataSample
...
Dim DataSource As New FlatDataSource()
DataSource.ItemsSource = DataSample
'alternatively,
Dim DataSample As New SalesDataSample()
Dim DataSource As New FlatDataSource()
Dim DataConnectionSettings As New FlatDataConnectionSettings()
DataConnectionSettings.ItemsSource = DataSample
DataSource.ConnectionSettings = DataConnectionSettings
Me.PivotGrid.DataSource = DataSource

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic serves as an overview of the data sources supported by the xamPivotGrid™ control.

This topic explains how to use an Excel file as a data source for the xamPivotGrid.

This topic explains how to use the XmlaDataSource class for displaying olap data from Microsoft Analysis Services in the xamPivotGrid™.