This is not a new question at all, after all. Generating a table-of-contents has been requested since the old jfree.org days, years before Pentaho came to life. But a gross lack of capabilities in the layouter and the engine itself prevented any serious attempt at that time. But as years passed by, the engine matured, subreports became a reality, the layouter was replaced (several times) and with the Citrus release element-attributes, report-bundles and report-preprocessors became a reality. So it's time to revisit this feature request one more time.
So how do I get the new feature?
The table-of-contents feature is implemented as two extensions modules - one for the reporting engine and one for the report-designer. In addition to that, I had to extend the engine-core in the parser and report data processor to adapt it to the new requirements.
The feature requires at least Pentaho Reporting 3.6.1. It therefore needs either a BI-Server 3.6.0 or a BI-Server 3.5.2 with an upgraded reporting-engine. Simply follow the instructions on how to replace the reporting engine in BI-Server 3.5.2, and you shall be ready to go.
Now download the updated classic-engine-core, extensions-toc and report-designer-extensions-toc. Place the classic-engine-core and the extensions-toc into "pentaho/WEB-INF/lib" on your server and into "report-designer/lib" in your report-designer. Put the "report-designer-extensions-toc" into the "report-designer/lib" directory as well. To update PRD, you could also just grab a CI build of the PRD assembly to get the full product.
How do I use the new Table-of-Contents feature?
When you start the Pentaho Report Designer the next time, you will see a second sub-report icon in the list of available elements. The icon will be labelled "table-of-contents". Just drag it into your report. It behaves like any other subreport, so both banded and inline-mode are available.
However, I do recommend that you use it in banded-mode, as table-of-contents usually span the full page-width anyway and banded subreports are more performant than inline subreports.
You can start designing your table-of-contents like any other subreport by double-clicking on it. The data-source is already preconfigured to show the fields that will be available.
- "item-title" - a object/text computed by the title-field or title-formula property of the ToC-element.
- "item-page" - the page the current item was found. If the item spans several pages, the first page is returned.
- "item-index" - the item-index as text. The index counts the number of group-starts for each defined group. The string looks somewhat like this "2.5.9"
- "item-index-array" - the item-index as array of Integer values. Perfectly suitable to be printed via the CSVText function or any other expression.
How do I control what contents are included in the ToC-generation?
The actual generation is carried out by a custom function, which receives its configuration from a bunch of attributes on the "table-of-contents" element. The fields and formulas defined in there are evaluated in the context of the report that contains the table-of-contents element.- "group-fields" - Defines both the depth of the data-collection and the fields from where to read the "group-value-X" values. If the group-field given in the array is empty, the field value will be read from the current relational group and in the details-processing, the value will be null. If the "group-fields" list is empty, an automatic mode is activated that collects all groups extracting the group-value from the relational group.
- "collect-details" - Defines, whether detail items should be included in the data-collection. Be aware that this can easily blow up your memory consumption, as we have to hold the collected items in memory. I would not use this on a "million-rows" report.
- "title-formula" - Defines a formula that is evaluated when a new item has been collected. The formula will only be evaluated if the title-field is not set. "title-field" - Defines a field in the master-report that will be read for a valid item-title.
- "index-separator" - Defines the separator text that is used between the index-elements. It defaults to ".".
3 comments: