Document TemplateConditional Columns
IN THIS PAGE
Tables in a document template can use parent level logical fields to control visibility of columbs.
Sample Data
{ "static": { "showContact": true, "showCountry": true, "showRegion": true, "showCity": true, "showAddress": false, "showPostalCode": false, "showPhone": false, "showFax": false, "customer": [ { "CustomerID": "ALFKI", "CompanyName": "Alfreds Futterkiste", "ContactName": "Maria Anders", "ContactTitle": "Sales Representative", "Address": "Obere Str. 57", "City": "Berlin", "Region": null, "PostalCode": "12209", "Country": "Germany", "Phone": "030-0074321", "Fax": "030-0076545" }, { "CustomerID": "ANATR", "CompanyName": "Ana Trujillo Emparedados y helados", "ContactName": "Ana Trujillo", "ContactTitle": "Owner", "Address": "Avda. de la Constitución 2222", "City": "México D.F.", "Region": null, "PostalCode": "05021", "Country": "Mexico", "Phone": "(5) 555-4729", "Fax": "(5) 555-3745" }, { "CustomerID": "ANTON", "CompanyName": "Antonio Moreno Taquería", "ContactName": "Antonio Moreno", "ContactTitle": "Owner", "Address": "Mataderos 2312", "City": "México D.F.", "Region": null, "PostalCode": "05023", "Country": "Mexico", "Phone": "(5) 555-3932", "Fax": null }, { "CustomerID": "AROUT", "CompanyName": "Around the Horn", "ContactName": "Thomas Hardy", "ContactTitle": "Sales Representative", "Address": "120 Hanover Sq.", "City": "London", "Region": null, "PostalCode": "WA1 1DP", "Country": "UK", "Phone": "(171) 555-7788", "Fax": "(171) 555-6750" } ] } }
This data has a single top level record which includes a number of logical fields, which we will reference in the table column definition.
Instead of looping at the top level *root like our other example document templates, This document template with loop over an array called "customer" .
Using the "visiblefield" Property of Columns
{ "info": { "width": "11in", "height": "8.5in" }, "table": { "area": { "border": { "style": "Single" } }, "columns": [ { "width": "64pt" }, { "width": "100pt" }, { "width": "100pt", "visiblefield": "showContact" }, { "width": "100pt", "visiblefield": "showContact" }, { "width": "100pt", "visiblefield": "showAddress" }, { "width": "100pt", "visiblefield": "showCity" }, { "width": "100pt", "visiblefield": "showRegion" }, { "width": "64pt", "visiblefield": "showPostalCode" }, { "width": "64pt", "visiblefield": "showCountry" }, { "width": "54pt", "visiblefield": "showPhone" }, { "width": "54pt", "visiblefield": "showFax" } ], "body": { "sections": [ { "source": "customer", "sections": [ { "source": "*header", "rows": [ { "textformat": { "color": "White" }, "area": { "fill": { "color": "#333333" } }, "cells": [ { "text": "Customer ID" }, { "text": "Company Name" }, { "text": "Contact Name" }, { "text": "Contact Title" }, { "text": "Address" }, { "text": "City" }, { "text": "Region" }, { "text": "PostalCode" }, { "text": "Country" }, { "text": "Phone" }, { "text": "Fax" } ] } ] }, { "rows": [ { "cells": [ { "field": "CustomerID" }, { "field": "CompanyName" }, { "field": "ContactName" }, { "field": "ContactTitle" }, { "field": "Address" }, { "field": "City" }, { "field": "Region" }, { "field": "PostalCode" }, { "field": "Country" }, { "field": "Phone" }, { "field": "Fax" } ] } ] } ] } ] } } }
The document produced by this will hide columns that have a "visiblefield" with values of 'false' .
Changing the top level data values
{ "static": { "showContact": true, "showCountry": true, "showRegion": false, "showCity": true, "showAddress": false, "showPostalCode": false, "showPhone": true, "showFax": true, .. }
Changing the values in the top level fields changes the generated document, which you can use for user selected columns.