Assume you have a sporting event or league. The results are likely stored in a database and need to be displayed on a website. You can use the Fetch API to retrieve the data from the backend, although this document assumes the data has already been retrieved and is available as an array of records. This array must be in the correct order, but the source function can filter and sort the array on the fly within the report engine.
This document explains how to easily define headers and footers and arrange record grouping using compare function. Each header function returns HTML based on static text and parameters currentRecord, objWork, and splitPosition. Each footer function returns HTML based on static text and parameters previousRecord, objWork, and splitPosition. It is very flexible, but you have to create the HTML yourself; don't expect a WYSIWYG editor.
A report consists of a report header and footer, which can be text, HTML, or both. The report contains one or more section levels:
In case you want to implement a running counter, you have to initialize/reset it in the right place. It can be achieved by putting some code in the relevant header:
If you only want to initialize objWork.runningCounter at the beginning of the report you can achieve that by putting the right code in reportDefinition.headers[0]. I call it property runningCounter, but you can give it any name you want.
You have to increase the running counter somewhere in your code because... otherwise it is not running ;-) for example:
Most of the time you don't need to manage a running counter in javascript! Most likely data comes from a database which can be queried by SQL. Use the SQL WINDOW function ROW_NUMBER or RANK to do the hard work.
Below source code I created to make this all work. It is kind of wrapper function for all headers and footers. Feel free to copy paste it and use it in your own module.
objWork is a javascript object that is passed as the second argument to createOutput function (optional argument, default {}). It is passed on as shallow copy to headers functions, footers functions, compare function, init function, source function and display function. All these functions share this object. You can use it for example for configuration information or color scheme. objWork is automagically extended with { rawData: thisData }. For example createOutput(reportDefinition, { font: 'Arial', font_color: 'blue' })(thisData).