New to Telerik ReportingStart a free 30-day trial

Creating Nested Hierarchy with SubReports

Using a DataSource in the SubReport item allows you to bind the child report directly to a filtered subset of the parent's data, making the hierarchy more intuitive and reduces using parameters for building the hierarchical structure. This approach of implementing a master-detail report scenario does not use different data sources in both reports, as demonstrated in the Creating Master-Detail Reports article.

The main benefits of this approach are:

  • No need to define and pass parameters manually. All the data is available in the parent report.
  • Works naturally with hierarchical object models or JSON data.
  • Cleaner and more maintainable for multi-level hierarchies.

The example in this tutorial shows how to present and organize a report when the used data has a nested (hierarchical) structure. The JSON data for this report represents a collection of Categories. Each category contains a nested list of its Products.

A complete step-by-step video is available here:

To design a report that represents a hierarchy:

  1. Create a new report (for example, CategoriesReport.trdp). You will use it as the main (parent) report to display categories.

  2. Create a JSONDataSource item using the nested JSON collection for Categories and Products.

  3. Use the Table Wizard to create a table bound to the JSON source.

    Categories Products Default Table
  4. Select the generated TextBox for the Products field (the TextBox bound to Fields.Products).

  5. Navigate to the Components tab and click SubReport. Thus, the TextBox item is replaced by a SubReport item.

  6. Using the search box, navigate to the Bindings section and add a new binding for the DataSource field and set the Expression to "=Fields.Products". Thus, the SubReport item will be mapped to the Products list of the respective category record.

    DataSource Binding
  7. Navigate to the INNER REPORT section and select the UriReportSource Type. Now, you need to create a separate report that will be used as a container for the products for each category.

  8. Create another report (ProductsReport.trdp).

  9. Remove the default header/footer and add two TextBox items (or other Report items according to the data you need to display).

  10. Using the search box, navigate to the Value field and bind to =Fields.ProductName and =Fields.Price respectively. Save the child report.

  11. Go back to the CategoriesReport.trdp report and set the newly created ProductsReport.trdp as Uri for the UriReportSource.

    Specify Uri report
  12. Click the Preview button. In the report, you will see the products for each category group.

    Preview Categories Products

See Also

In this article
See Also
Not finding the help you need?
Contact Support