All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Bind a Report to a Transformation-Based Data Source (Runtime Sample)

  • 4 minutes to read

This example demonstrates how to create a federated data source that unfolds another data source's complex objects and flattens them in a simple data set.

Data Source Structure Transformation

Create a JSON Data Source

Create a JsonDataSource object that retrieves data from the Products.json file.

Products.json
[
  {
    "CategoryId": 1,
    "CategoryName": "Beverages",
    "Description": "Soft drinks, coffees, teas, beers, and ales",
    "Products": [
      {
        "ProductId": 1,
        "ProductName": "Chai",
        "SupplierId": 1,
        "CategoryId": 1,
        "QuantityPerUnit": "10 boxes x 20 bags",
        "UnitPrice": 18.0000,
        "UnitsInStock": 39,
        "UnitsOnOrder": 0,
        "ReorderLevel": 10,
        "Discontinued": false,
        "Supplier": null
      },
      {
        "ProductId": 2,
        "ProductName": "Chang",
        "SupplierId": 1,
        "CategoryId": 1,
        "QuantityPerUnit": "24 - 12 oz bottles",
        "UnitPrice": 19.0000,
        "UnitsInStock": 17,
        "UnitsOnOrder": 40,
        "ReorderLevel": 25,
        "Discontinued": false,
        "Supplier": null
      }
    ]
  },
  {
    "CategoryId": 2,
    "CategoryName": "Condiments",
    "Description": "Sweet and savory sauces, relishes, spreads, and seasonings",
    "Products": [
      {
        "ProductId": 3,
        "ProductName": "Aniseed Syrup",
        "SupplierId": 1,
        "CategoryId": 2,
        "QuantityPerUnit": "12 - 550 ml bottles",
        "UnitPrice": 10.0000,
        "UnitsInStock": 13,
        "UnitsOnOrder": 70,
        "ReorderLevel": 25,
        "Discontinued": false,
        "Supplier": null
      },
      {
        "ProductId": 4,
        "ProductName": "Chef Anton's Cajun Seasoning",
        "SupplierId": 2,
        "CategoryId": 2,
        "QuantityPerUnit": "48 - 6 oz jars",
        "UnitPrice": 22.0000,
        "UnitsInStock": 53,
        "UnitsOnOrder": 0,
        "ReorderLevel": 0,
        "Discontinued": false,
        "Supplier": null
      }
    ]
  }
]
using DevExpress.DataAccess.Json;

//...

// Create a JSON data source.
JsonDataSource jsonDataSource = new JsonDataSource();
Uri fileUri = new Uri("Products.json", UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
jsonDataSource.Fill();

The data source includes a nested Products collection.

JSON Data in the Field List

Create a Federation Data Source

Create a FederationDataSource object. Use a TransformationNode instance to transform the JSON data source into a flat structure.

using DevExpress.DataAccess.DataFederation;

// ...

// Create a Federation data source.
FederationDataSource federationDataSource = new FederationDataSource();
Source jsonSource = new Source("json", jsonDataSource, "");
SourceNode sourceNode = new SourceNode(jsonSource);
TransformationNode transformationNode = new TransformationNode(sourceNode) {
    Alias = "Transformation",
    Rules = { new TransformationRule { ColumnName = "Products", Unfold = true, Flatten = true } }
};
federationDataSource.Queries.Add(transformationNode);

The data source exposes the flattened structure.

Federation Data Source

Bind a Report to the Federation Data Source

Create a new report and construct a layout similar to the described layout. Use the report's DataSource and DataMember properties to bind it to a federated data source.

using System.ComponentModel;
using System.Drawing;
using DevExpress.XtraReports.UI;

// ...

// Create a report and bind it to the Federation data source.
XtraReport1 report = new XtraReport1();
report.DataSource = federationDataSource;
report.DataMember = "Transformation";

View the Result

Initialize the End-User Report Designer or Document Viewer and display the report. Refer to the following topics for instructions on how to do this on different platforms:

The following code sample demonstrates how to display the report in the Windows Forms Document Viewer:

ReportDesignTool designTool = new ReportDesignTool(CreateReport());
designTool.ShowRibbonDesignerDialog();

See Also