Products Technologies Demo Docs Blog Support Company

Merging Nested Repeating Blocks in ReportingCloud

Thanks to the data source excerpt file concept, it is very easy to create templates with complex structures such as nested repeating blocks. A data source excerpt file is used to fill the drop-down lists of the template editor with proper merge fields, relations and dummy data for a template preview. A data source excerpt file is not the actual data that is used to merge the template. It helps to design the templates and to insert the proper field names. In this article, the following .NET…

Merging Nested Repeating Blocks in ReportingCloud

Thanks to the data source excerpt file concept, it is very easy to create templates with complex structures such as nested repeating blocks. A data source excerpt file is used to fill the drop-down lists of the template editor with proper merge fields, relations and dummy data for a template preview. A data source excerpt file is not the actual data that is used to merge the template. It helps to design the templates and to insert the proper field names.

In this article, the following .NET classes are used as the data source structure for the ReportingCloud merge process:

public class Report
{
    public Report()
    {
        this.Sales = new List<Sale>();
    }

    public string Name { get; set; }
    public List<Sale> Sales { get; set; }
}

public class Sale
{
    public Sale()
    {
        this.Items = new List<Item>();
    }

    public int Id { get; set; }
    public List<Item> Items { get; set; }
}

public class Item
{
    public int Qty { get; set; }
    public float Price { get; set; }
    public Product Product { get; set; }
}

public class Product
{
    public string Name { get; set; }
}

Report is the master template which reflects the complete template. In other words, the complete template is merged with the number of rows in this master template. The following code shows the instantiated .NET object that is used:

Report report = new Report();
report.Name = "Monthly Sales Report";

report.Sales.Add(new Sale()
{
    Id = 1,
    Items = new List<Item>()
    {
        new Item()
        {
            Price = 256.2F,
            Product = new Product()
            {
                Name = "ReportingCloud"
            },
            Qty = 5
        },
        new Item()
        {
            Price = 424.2F,
            Product = new Product()
            {
                Name = "TX Text Control"
            },
            Qty = 3
        }
    }
});

This object has 1 Sale object which consists of 2 different Item objects. In the template, a list of all Sale items should be visualized as a merge block. Inside this outer merge block, all Item objects should get listed as a nested merge block. The following screenshot shows this structure in the template:

Merging nested repeating blocks in ReportingCloud

But how to insert these blocks in the ReportingCloud template designer?

First, we need to create a serialized JSON string from the object. You can create this string manually or simply serialize this object using the JavaScriptSerializer class:

var json = new JavaScriptSerializer().Serialize(report);

The results will look similar to this:

{
   "Name":"Monthly Sales Report",
   "Sales":[
      {
         "Id":1,
         "Items":[
            {
               "Qty":5,
               "Price":256.2,
               "Product":{
                  "Name":"ReportingCloud"
               }
            },
            {
               "Qty":3,
               "Price":424.2,
               "Product":{
                  "Name":"TX Text Control"
               }
            }
         ]
      }
   ]
}

In the ReportingCloud Portal, open My Datasource Excerpts and create a new excerpt file by adding a name and pasting the JSON string to the excerpt input. As ReportingCloud expects an array of objects as the data source, enclose the complete string with square brackets.

Merging nested repeating blocks in ReportingCloud

Now, when designing the template in the ReportingCloud template designer, the merge blocks are listed in the available Insert Merge Block drop-down button. In the ReportingCloud Portal, create a new template in the My Templates area. Before editing the template, select the created datasource excerpt file from the available sources and confirm with Edit Template.

Merging nested repeating blocks in ReportingCloud

  1. In the opened template designer, click on sales from the Insert Merge Block drop-down to insert the outer merge block sales.

  2. Set the input position into the block row and add a table row using the right-click context menu.

    Merging nested repeating blocks in ReportingCloud

  3. Set the input position into the newly created table row and choose items from the Insert Merge Block drop-down to insert the nested block items.

  4. In the opened dialog, select the 2 columns price and qty and confirm with OK.

    Merging nested repeating blocks in ReportingCloud

A second nested block has been inserted into the outer block:

Merging nested repeating blocks in ReportingCloud

When previewing this template, the expected results of the nested block are rendered successfully:

Merging nested repeating blocks in ReportingCloud

Test this on your own and create a free trial account today.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETCloudReporting

Web.TextControl: Adaptive Merge Field Drop-down Lists

A change you might not have noticed in Web.TextControl after X14 Service Pack 1, is the adaptive display of merge fields and available tables in the drop-down lists Insert Merge Field and Insert…


ASP.NETReportingWindows Forms

Creating Templates: Typical Invoice Elements

This article shows the structure of a typical invoice template that can be used with TX Text Control and ReportingCloud.


CloudReportingRelease

ReportingCloud Monthly Payment Available

We just released ReportingCloud monthly subscriptions that will be auto-renewed, if not cancelled.


ASP.NETReportingConference

See Text Control at THAT Conference in Wisconsin

Next month, we are going to sponsor THAT Conference and will be on-site with a booth.


ASP.NETReportingWindows Forms

Different Ways to Create Documents using Text Control Products

There are many ways to create documents using Text Control products. This article gives an overview of different approaches using our products.