KoolReport's Forum

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

Datagrid / DataTable clientRowGroup doesn't seem to know how to sum negative amounts? #1776

Closed paulo opened this topic on on Dec 18, 2020 - 2 comments

paulo commented on Dec 18, 2020

Hi, I am using Datagrid with clientRowGroup (really happy you guys added this group feature!).
However, when listing amounts with negative, it is not taking into consideration when doing the totals. The order question is how to format with $ and decimal points on the group row? thanks

Here is my code:

       "clientRowGroup" => [
                "name" => [
                    'direction' => 'asc',
                    'calculate' => [
                        'totalAmount' => [
                            'sum',  //'sum', 'count', 'avg', 'min', 'max'
                            'amountFormatted'
                        ],
                    ],
                    "top" => "<td colspan='999'>{expandCollapseIcon} {name} | Total: {totalAmount}</td>",
                ],
            ],

For instance , I have two rows of data : BBQ Joint $579.00 BBQ Joint $-579.00

The row group total instead of showing 0 (zero) it is showing 1158 BBQ Joint | Total: 1158

The negative amount comes from a call to an API, and all the amountFormated is doing is dividing by 100:

->pipe(new CalculatedColumn(array(
                    "amountFormatted" =>"{amount}/100"
                )))

thanks

Sebastian Morales commented on Dec 21, 2020

Paulo, pls open the file koolreport/datagrid/DataTables.php and replace the following string:

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

with:

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

We will add this fix for the next version of DataTables. Cheers,

paulo commented on Dec 21, 2020

thank you. It worked

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

DataGrid