BI-Publisher RTF Template: Repeat colums or rows horizontally first before new page

2 min read 05-10-2024
BI-Publisher RTF Template: Repeat colums or rows horizontally first before new page


Breaking the Mold: Repeating Columns and Rows Horizontally First in BI Publisher RTF Templates

Problem: You're working with a BI Publisher RTF template and need to display a large dataset that doesn't fit comfortably on a single page. The default behavior of BI Publisher is to break the data into multiple pages by adding rows, but you need to prioritize horizontal expansion (repeating columns) before moving to new pages.

Scenario: Imagine you're creating a report showing sales data for different products across multiple regions. You have a lot of data, but want to showcase all products within a single region on the same page before moving to the next region.

Original Code:

<?for-each:REGION?>
  <fo:table>
    <fo:table-column column-width="proportional-column-width(1)"/>
    <fo:table-header>
      <fo:table-row>
        <fo:table-cell>Region: <?REGION_NAME?> </fo:table-cell>
      </fo:table-row>
    </fo:table-header>
    <fo:table-body>
      <?for-each:PRODUCT?>
        <fo:table-row>
          <fo:table-cell>
            <?PRODUCT_NAME?>
          </fo:table-cell>
        </fo:table-row>
      <?for-each:PRODUCT?>
    </fo:table-body>
  </fo:table>
<?for-each:REGION?>

This code will display each region as a new table on a separate page. The goal is to display all products within each region on the same page before moving to the next region.

Solution:

To achieve this, you need to leverage the power of the fo:flow element within your BI Publisher RTF template. fo:flow allows you to control how data is displayed and broken across pages.

Modified Code:

<?for-each:REGION?>
  <fo:flow flow-name="region-flow">
    <fo:table>
      <fo:table-column column-width="proportional-column-width(1)"/>
      <fo:table-header>
        <fo:table-row>
          <fo:table-cell>Region: <?REGION_NAME?> </fo:table-cell>
        </fo:table-row>
      </fo:table-header>
      <fo:table-body>
        <?for-each:PRODUCT?>
          <fo:table-cell>
            <?PRODUCT_NAME?>
          </fo:table-cell>
        <?for-each:PRODUCT?>
      </fo:table-body>
    </fo:table>
  </fo:flow>
<?for-each:REGION?>

Explanation:

  1. We've wrapped the entire table for each region within an <fo:flow> element.
  2. This flow is named "region-flow" for easy identification.
  3. The fo:flow element tells BI Publisher to prioritize horizontal expansion (filling the page with columns) before breaking into a new page.

Additional Insights:

  • You can control the number of columns displayed on a single page using the fo:table-column element and its column-width attribute. This allows you to adjust the layout to your specific needs.
  • You can use a combination of fo:flow and fo:break-before to create more complex layouts. For instance, you can have a separate fo:flow for each product category within a region, ensuring that products within the same category are displayed on the same page.

Benefits:

  • Improves readability by displaying related data (products within a region) together.
  • Makes efficient use of page space by prioritizing horizontal expansion.
  • Simplifies the layout design process, allowing for greater control over data presentation.

Conclusion:

By embracing the power of the fo:flow element in your BI Publisher RTF templates, you can easily customize the layout of your reports and prioritize horizontal expansion to improve readability and efficiency.

References:

This guide will help you achieve the desired horizontal data flow and customize the appearance of your BI Publisher reports.