KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Row Groups #850

Closed rodger_kz opened this topic on on May 3, 2019 - 1 comments

rodger_kz commented on May 3, 2019

How do you add add decimal points to a calculated field in row groups

Table::create(array(
    ...
    "grouping"=>array(
        "year"=>array(
            "calculate"=>array(
                "{sumAmount}"=>array("sum","amount")
            ),
            "top"=>"<b>Year {year}</b>",
            "bottom"=>"<td><b>Total of year {year}</b></td><td><b>{sumAmount}</b></td>"
        ),
    ),
))
KoolReport commented on May 6, 2019

You may follow this example:

Table::create(array(
    ...
    "grouping"=>array(
        "year"=>array(
            "calculate"=>array(
                "{sumAmount}"=>array("sum","amount"),
                "{avgAmount}"=>array("avg","amount")
                "{maxAmount}"=>array("max","amount")
            ),
            "top"=>function($calculated_results){
                return "Number items:".$calculated_results["count"];
            },
            "bottom"=>function($calculated_results){
                return "Sum amount:".$calculated_results["{sumAmount}"];
            },
        ),
    ),
));

You may see in "top" and "bottom" anonymous function, you receive calculated results in an array, so basically you may use the number_format() function to format them ( to add decimals that you want) before return the string for group top and group bottom.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

None