Condition-based table column printing

A table layout has a lot of advantages for displaying lists of structured data. Sometimes you might need to hide table columns depending on available data.

In this tutorial you will learn to:
Use a parameter to hide a table column
Allow other table columns to take up remaining space

1 Use a parameter to hide a table column

Let's take the example of a monthly timesheet. An employee tracks working time and personal expenses for the company, e.g. costs for car parking that she is going to get reimbursed. The printed timesheet should show the working hours and a description. Personal expenses are also shown but only in case they actually occurred.

We already created a table with all needed parameters (learn here how to create a table and populate it with data). When previewing our layout all columns of the table are printed. The table footer contains sums for the working hours and expenses.

Now we want to display the expenses column only when it sums up to more than 0. We achieve this by defining a print condition on the column header. Let's double click the expenses header cell and set a print if condition in the print settings:
${sum_expenses} > 0
Because it's a Python expression you could also simply write ${sum_expenses}
${sum_expenses} of 0 will be false (have a look at the expression syntax in the user guide for further explanations).

2 Allow other table columns to take up remaining space

While we were able to hide the column, our printed report doesn't look that pretty yet by leaving an empty space. That's why we use another print setting - grow weight. It helps to define how to distribute remaining space when columns are missing.

If we set the grow weight to 1 for all columns the space will be distributed evenly among the remaining columns.
However, as the description takes most space in the timesheet we want it to expand exclusively. Therefore, we only set the grow weight of the description. Other columns will keep their width.

What you can do to control column display

Set a print condition on a header cell to control the appearance of the whole column.

Apply grow weight on header cells to define consumption of remaining space:
No grow weight: the cell keeps its width
Equal values on all cells: space is distributed equally
Distinguished values on cells: higher value gets more space

Try it yourself: Download the report of this tutorial
Read here how to import the report into ReportBro Designer.

Want to know more about tables? Read our tutorials for
Creating tables,
Table grouping and
Table with dynamic columns

By the way, ReportBro is also available for everyone as open-source on github (see Download page). Star us on github if you like what you see!