Table-layout: An easier way to build tables

At the moment I am working on the cross-tabbing code inside the Pentaho Reporting Engine. Ever since our old JFreeReport days this feature was on the list of things to do, but never quite made it up to the top of the heap.

While roaming through the existing and experimental cross-tab code, I found several easy ways to break the layout. Set a cell’s width or height wrong, and you are hosed. Dynamic height? Layout kaput! Null-values? Table goes down the drain.

We need something better!

Right now, we are using unrelated bands stacked together to get some appearance of a tabular structure. This works for the simple case, but anything complex causes trouble, similar to using CSS-styled DIVs in HTML to emulate tables. So we really need true tables to make it work.

Now, instead of building a one-off layout strategy, I am going to write this table-layout in a more general way. This way, you can apply it to groups or even ordinary sub-bands.

For groups, you will be able to set the group’s layout property to “table”. The group-body, the group-header, footers and other bands will automatically form a single cell in the table by default. So nothing breaks, nothing changes.

The magic starts when you apply the layouts “table-body”, “table-row” or “table-cell” to the various sub-bands. The bands then will be merged into a single flat table structure which shares borders and which synchronizes the layout.

There are several immediate advantages from the “true table layout”(tm):

  • Your header now controls the width of all cells. Increase the width of the header, and the details band follows. Even in design mode.
  • Borders merge properly, so that you get a proper grid rendered. No more double width borders then.
  • absolutely no overlapping cells
  • Table-exports can translate this structure directly into their documents. No more guessing why your cells have a empty cell here.
  • Technically, if you are willing to pay the price, we can have a complete auto-layout where the width of cells is based on the content printed in them. As in web-browsers, this is slow and memory consuming. Might be just a nice to have for slick demos. You may not want to use that in real world reports.

The table-layout will come within the next few weeks, along with the missing pieces of the cross-tabbing. Stay tuned ..

9 thoughts on “Table-layout: An easier way to build tables

  1. mcloud

    You might want to check the table component in newer JasperReports/iReport. It’s not super, but it does it’s job without breaking.

    Reply
  2. Thomas Morgner

    The Jasper layouter is not suitable for the Pentaho Reporting engine. At Pentaho we believe that all layouts can be computed in memory and that report layout generation can be solved in a streaming fashion without swapping state to disk. I’d rather not change that advantage of our layout system ;)

    I took my inspiration for the actual specification and the layouting rules from the CSS3-Table standard instead. Theirs is easy to understand and as far as I can tell feature complete. It also means I dont have to document the way it behaves, as I just point everyone to the standard :)

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>