Cell Repeater

Desired Output

In DocuMotor, it is possible to populate tables horizontally, while also controlling their length, by using a cell repeater binding. An overview of this function is presented in the image below:

Sample Data

The data set that will be used in this tutorial can be found below:

{
	"Cars": [
		{
			"Brand": "Volkswagen",
			"Model": "Cabriolet",
			"Color": "Puce",
			"Year": 1993
		},
		{
			"Brand": "Lincoln",
			"Model": "Town Car",
			"Color": "Green",
			"Year": 1989
		},
		{
			"Brand": "GMC",
			"Model": "Envoy XUV",
			"Color": "Indigo",
			"Year": 2005
		},
		{
			"Brand": "Ford",
			"Model": "Explorer",
			"Color": "Puce",
			"Year": 1994
		},
		{
			"Brand": "Dodge",
			"Model": "Journey",
			"Color": "Maroon",
			"Year": 2012
		},
		{
			"Brand": "Dodge",
			"Model": "Journey",
			"Color": "Pink",
			"Year": 2010
		},
		{
			"Brand": "Nissan",
			"Model": "Maxima",
			"Color": "Aquamarine",
			"Year": 2012
		},
		{
			"Brand": "Kia",
			"Model": "Rio",
			"Color": "Green",
			"Year": 2005
		},
		{
			"Brand": "Nissan",
			"Model": "Sentra",
			"Color": "Fuscia",
			"Year": 2008
		},
		{
			"Brand": "Cadillac",
			"Model": "XLR",
			"Color": "Crimson",
			"Year": 2005
		}
	]
}

Word Template

The Word template, along with all the required bindings, that are used in this tutorial can be downloaded using the button below:

Transformation

In order for the cell repeater to function properly, a particular model needs to be used when transforming the data. More specifically, the following needs to be included in the transformation:

{
  "options":{
    "direction": "lrtb" 
  },
  "cells":[{"testkey":"testvalue"}] 
}
  • options (case sensitive, required) – defines the general options for the cell repeater processing.
  • direction (case sensitive, required) – string parameter. Defines the direction with which the cells will be expanded. Currently, only the following value is supported for this parameter:
    • lrtb” (left-right-top-bottom)
  • cells (case sensitive, required) – list parameter. This is where the array that holds the table’s data is added.

In this tutorial, the transformation below is used:

{
  "cellRepeater": {
    "options": {
      "direction": 'lrtb'
    },
    "cells": Cars[]
  }
}

This will result in the following output:

{
  "cellRepeater": {
    "options": {
      "direction": "lrtb"
    },
    "cells": [
      {
        "Brand": "Volkswagen",
        "Model": "Cabriolet",
        "Color": "Puce",
        "Year": 1993
      },
      {
        "Brand": "Lincoln",
        "Model": "Town Car",
        "Color": "Green",
        "Year": 1989
      },
      {
        "Brand": "GMC",
        "Model": "Envoy XUV",
        "Color": "Indigo",
        "Year": 2005
      },
      {
        "Brand": "Ford",
        "Model": "Explorer",
        "Color": "Puce",
        "Year": 1994
      },
      {
        "Brand": "Dodge",
        "Model": "Journey",
        "Color": "Maroon",
        "Year": 2012
      },
      {
        "Brand": "Dodge",
        "Model": "Journey",
        "Color": "Pink",
        "Year": 2010
      },
      {
        "Brand": "Nissan",
        "Model": "Maxima",
        "Color": "Aquamarine",
        "Year": 2012
      },
      {
        "Brand": "Kia",
        "Model": "Rio",
        "Color": "Green",
        "Year": 2005
      },
      {
        "Brand": "Nissan",
        "Model": "Sentra",
        "Color": "Fuscia",
        "Year": 2008
      },
      {
        "Brand": "Cadillac",
        "Model": "XLR",
        "Color": "Crimson",
        "Year": 2005
      }
    ]
  }
}

Binding

The main binding of this function is the following:

{“BindingType”:”RepeatTableCells”,”BindingKey”:”sampleKey”}

The binding must enclose the entire table and not only a row or a cell, as seen in the example below. In the binding, sampleKey needs to be replaced with the array that holds the information that is supposed to be displayed in the table’s cells. In this case, sampleKey is replaced with cellRepeater.

The table’s first cell is used as a template for the remaining cells, but despite that, all cells in the template need to be bound to the corresponding keys in the output data. For example, in this tutorial, the word Brand is bound to DocuMotor’s output data using the following field binding:

{“BindingType”:”Field”,”BindingKey”:”Brand”}

Furthermore, the number of cells in the first row of the table in the template defines how many cells will be used for each row of the final document, and by extension the table’s size. It is also worth mentioning that besides expanding the table’s cells and rows, in case less data than the cells in the template is outputted, the table template will shrink to fit the size of the data.

Result

With a cell repeater binding, it is possible to populate the cells of a table horizontally instead of vertically while starting from different starting points and controlling the table’s length.