KoolReport's Forum

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

Datagrid: Simple column group sum not working for negative numbers #2153

Open Stephen Bunt opened this topic on on Jun 22, 2021 - 4 comments

Stephen Bunt commented on Jun 22, 2021

This has got to be a simple question but as a newbie, I don't know what I'm doing wrong. Group summation working well, except when there are negative values in the column. 12 + -12 = 24? Below is my clientRowGroup. Any direction appreciated.

    "clientRowGroup" => array(
        "progsite_code" => array(
            'calculate' => [
                'totalSite' => [
                    'sum',  
                    'tran_amount',
                    "format" => "function(value) {return '$' + value.toFixed(2);}",
                ],

            ],
            "bottom" => "<td colspan='999' align='right' style='background-color: #FBBC05;'><b>Program Site: {progsite_code} | Total: {totalSite}</b></td>",
        ),
        "child_fullname" => array(
            'calculate' => [
                'totalChild' => [
                    'sum',  
                    'tran_amount',
                    "format" => "function(value) {return '$' + value.toFixed(2);}",
                ],
            ],
            "bottom" => "<td colspan='999' align='right' style='background-color: #DEEFFF;'><b>{child_fullname} | Total: {totalChild}</b></td>",
        ),
    ),
Sebastian Morales commented on Jun 23, 2021

Pls let us know which version of Datagrid you are using? Also open the file koolreport/datagrid/DataTables.php and go the these lines:

                        case "sum":
                            $reduceFunc = ...

and let us know the rest of $reduceFunc line's content. Tks,

Stephen Bunt commented on Jun 23, 2021

Thanks for the quick reply. Datagrid is Version 5.0.1.

$reduceFunc = "return a + 1*b.replace(/[^\d\.]/g, '');";

Sebastian Morales commented on Jun 28, 2021

Stephen, would you mind sending us some sample data (via support@koolreport.com email if you want) for us to test it for you. Tks,

Sebastian Morales commented on Jun 28, 2021

Oh, I realize this was an old bug in the DataTables' row grouping.

Pls either updating Datagrid package to the latest version or replace the line:

$reduceFunc = "return a + 1*b.replace(/[^\d\.]/g, '');";

with this one:

$reduceFunc = "return a + 1*b.replace(/[^\d\.\-]/g, '');";

and let us know if it fixes your row grouping issue with negative number.

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

DataGrid