Enhancements to pivot table functionality

Company founder Ebeneezer P. Jsreports has informed us that our bonuses this year will be determined by the number of blog posts we write, so you can look forward to seeing a lot more from me here in the coming months.

Let’s see, what to write about today? Here’s something. We just made some improvements to the pivot engine in jsreports. In case you aren’t familiar, the pivot feature lets you generate columns in a report on the fly from distinct values in the rows of your data source. To use it, check the “enable pivot” box in the designer (under Data & Groups -> Pivot, in the left panel).

report-designer-pivot

You’ll see two areas in the canvas: the non-shaded area between the two purple lines, in the center of the canvas above, is the “pivot column”–this is what will get repeated. You’ll get one copy of this column for each unique value in your pivot field (unless you turn on bucketing, in which case you could get one column for each distinct month, or year, for example).

The other, shaded area in the report is the reserved space for the generated columns. As columns are generated, they’ll fill this space.  If there are too many columns to fit in the shaded space, the report will expand horizontally to fit all columns. Any non-shaded space to the right, and any elements in that space, will be shifted rightward so that they remain in the same position relative to the right edge of the report.

Here’s what happens when you run the report:

jsreports-pivot-output

The pivot column has been repeated left-to-right across the reserved space. The logo remains positioned where it was on the canvas, because it was outside of the repeating pivot column. Each element in the pivot column aggregates the values for its particular grouping and pivot value.

That’s all there is to it. You could put whatever you want in the pivot cells and it will be cloned and any text expressions evaluated against the set of rows that make up that pivot cell.

JavaScript enthusiast at jsreports – building a better reporting solution for modern web applications