Creating tables
Printing lists of structured data is one of the most important use cases when exporting data to PDF, e.g. to print invoice items, statistics, shipping items. Using tables is a convenient and fast way to achieve the desired results in report template design.
In this tutorial you will learn to:1 Insert a simple table with header and footer
Tables can be configured on different levels:
- Table itself
- Table content
- Table header and footer element
- Individual table cell
One click on the table selects the table itself, double click into the table selects a table cell. Once a cell is selected only one click is needed to switch to other cells in the table. The whole content row, header or footer row can be selected by clicking the respective element in the menu panel on the left.
2 Set table columns and style header
Let's take the example of a simple shopping list. We want to print a list with 3 columns for each product:
- Position: the row number of the list
- Quantity: the amount of ordered items
- Product: the actual product we want to buy
In the first step we select the table and define the amount of columns to print. Next we select the table header in the menu panel to set the height and apply a background. We want the header to repeat on every page in case the list doesn't fit on one page, so we activate the print setting "repeat header".
Let's double click the first header cell to type the header title and continue filling the whole table header. The width of a cell can be adapted by setting an exact value in the detail panel or stretching/shrinking the cell directly. You can also directly add another column left or right to the selected one or delete the selected column.
3 Create a parameter list
It is possible to populate a table with static text but the more relevant use case would be to have 1 content row iterating a parameter list. Parameters are used to pass data from an application to ReportBro in order to fill the report with dynamic data.
Therefore, we need to add a parameter of type list:
shopping_list
Inside this list add the following parameters which specify the
fields of each list entry:
- quantity (number)
- product (text)
We don't have to explicitly create the parameter row_number as it is created automatically by ReportBro for parameter type list.
Finally, we add corresponding test data for the parameter list to be able to preview it in our table later.
4 Define printable content
Since we want the content row to iterate over our shopping_list we select our table and assign it as a data source to it. This allows us to access its parameters.
Now we fill the content row with the parameters of the shopping_list. All we have to do is setting the respective parameter as text value of the cell.
5 Print column sum in footer
A footer can be useful for printing summaries or sums. In our example we want to print the sum of shopping items (sum of quantity) to know how many items we have to expect in our basket.
We create one more individual parameter of type sum
(make sure it's not part of the shopping list parameter).
- total_quantity (sum)
To get what we need, we have to define the parameter in the expression that is used to build the sum, which is the quantity from our shopping list, hence ${shopping_list.quantity}. Only thing left now is to apply our new parameter to the footer cell.
Print it like a Bro
We are ready to give it a go and have a look at our result. Cool, ey?
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
Table grouping,
Condition-based table column printing 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!