Conditional Columns (2)

Conditional Columns covered how to include or exclude columns in a table using Boolean fields and expressions.

There may be times when you want to exclude a column in a table with repeating rows depending on the values of the data. For example, you may want to exclude a column if there is no data to display.

 

<<cc_ denotes a conditional column in the header row of a table.

 

Through Values of Column Data

Example 1

In this first example, we are displaying a table of customers and we only want to display the Middle Name column if at least one customer has a middle name. To achieve this, we need to check each middle name value to make sure there is data to display.

First, we create a new variable called $mNamesExist and set this to False <<$mNamesExist=false>>. We then loop through our customers <<rs_customers>> … <<es_customers>> and check if a middle name (mName) exists for any customer <<cs_{!isBlank(mName)}>>, if it does we set $mNamesExist to True <<$mNamesExist=true>>. We use the isBlank() function to check if the value of mName is null or blank. We can then conditionally display the Middle Name column based on the value of $mNamesExist by using the conditional column command <<cc_$mNamesExist>>.

In the supplied data file, no mName’s exist for any of the customers, resulting in $mNamesExist remaining false, which in turn results in the Middle Name column being removed from the output. The other columns increase proportionally in width so that the overall table width remains the same as in the template.

TRY: setting a value for mName.

 

Example 2

In this second example we are displaying a table of products and we only want to display the Discount column if at least one value exists for discount. To achieve this, we add together the values of discount and make the column conditional based on this total. This approach is useful if you also want to display a total value at the end of the column.

First, we create a new variable called $discountTotal to store the total value of all the discounts and set this to 0 <<$discountTotal=0>>. We then loop through our products <<rs_products>> … <<es_products>> and add the value of each discount to the total <<$discountTotal ={$discountTotal+ifBlank(discount,0)}>>. We use the ifBlank() method to convert the value of discount to 0 if it’s null or blank. We can then conditionally display the Discount column based on the value of $discountTotal by using the conditional column command <<cc_{$discountTotal>0}>>.

In the supplied data file, no discount’s exist for any of the products, resulting in $discountTotal being 0, which in turn results in the Discount column being removed from the output. The other columns increase proportionally in width so that the overall table width remains the same as in the template.

TRY: setting a value for discount.

Feedback

Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Invalid Input

Applies To

Docmosis-Java Tornado Cloud
Version(s) 4.4.0, 4.4.1, 4.4.2, 4.5.0 (Latest) 2.7, 2.7.1, 2.7.2, 2.7.3, 2.8.0, 2.8.1 (Latest) ALL

Related items