Products Technologies Demo Docs Blog Support Company

Merging Nested Repeating Blocks in ReportingCloud

ReportingCloud supports nested repeating blocks in merge templates through data source excerpt files. A serialized JSON excerpt defines the hierarchical structure of merge fields and blocks, which then populate the Insert Merge Block drop-down in the browser-based template editor.

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

TX Text Control X14 Service Pack 1 adds adaptive drop-down lists in Web.TextControl for merge fields and merge blocks. Selecting a master table filters the lists to show only related child tables…


ASP.NETReportingWindows Forms

Creating Templates: Typical Invoice Elements

Building an invoice template with TX Text Control uses JSON data, merge fields, repeating blocks, and Excel-compatible formulas. Line totals, tax, and discounts compute directly in the template…


CloudReportingRelease

ReportingCloud Monthly Payment Available

ReportingCloud now supports monthly subscription plans that auto-renew each billing cycle until cancelled. Subscribers manage active plans and view payment invoices through the online store…


ASP.NETReportingConference

See Text Control at THAT Conference in Wisconsin

Text Control is exhibiting at THAT Conference in Wisconsin Dells, a developer event known as the Summer Camp for Geeks that draws over 1,000 attendees for sessions on mobile, web, and cloud…


ASP.NETReportingWindows Forms

Different Ways to Create Documents using Text Control Products

Text Control offers four document creation paths: building from scratch via the ServerTextControl API, merging pre-designed templates with MailMerge using IEnumerable or DataSet sources, editing…

Share on this blog post on: