KoolReport's Forum

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

Footer In Group By For Sums #3389

Open iWorQ Systems opened this topic on on Nov 20, 2024 - 11 comments

iWorQ Systems commented on Nov 20, 2024

I was wondering if there was a way in the data grids to have a footer in the Group By?

Meaning instead of doing the sum of all the columns for the whole report only do the sum for the columns in each group?

DataTables::create([
                'name' => 'rowGroupTable',
                'dataStore' => $this->dataStore('result'),
                'plugins' => [
                    'Buttons',
                    'FixedColumns',
                    'FixedHeader',
                    'KeyTable',
                    'Responsive',
                    'RowReorder',
                    'Scroller',
                    'SearchPanes'
                ],
                'options' => [
                    'dom' => 'Blfrtip',
                    'buttons' => [
                    ],
                    'searching' => true,
                    'paging' => true,
                    'pageLength' => 100,
                    'order' => $this->params['order'],
                    'fixedHeader' => true,
                    'autoWidth' => false,
                    'columnDefs' => [
                        $width
                    ],       
                ],
                'clientRowGroup' => [
                    'groupby' => [
                        'direction' => 'asc',
                        'top' => '<td colspan="999">{expandCollapseIcon} ' . $groupbyTitle . ': {groupby}</td>',
                    ],
                ],
                'cssClass' => [
                    'table' => 'table table-bordered table-striped table-hover'
                ],
                'columns' => $columns,
                'showFooter' => $this->params['sum'],
                'fastRender' => true,
                'onReady' => 'function() {
                    arr = getOrderBy();
                    rowGroupTable
                    .order(arr)
                    .draw();
                    checkRecordCount();
                }',
            ]);

Here is our code snippet for how we handle our group by data table.

This Picture shows the general Idea of what we want.

Sebastian Morales commented on Nov 21, 2024

Each group of datagrid/DataTables can have its own header/footer row with calculated sum/count/etc like this:

    "clientRowGroup" => [
        "customerName" => [
            'direction' => 'asc', //'asc', 'desc'
            'calculate' => [
                'totalSales' => [
                    'sum', //'sum', 'count', 'avg', 'min', 'max'
                    'dollar_sales'
                    "format" => "function(value) {return value.toFixed(2);}",
                ], 
            ],
            "top" => "... {totalSales}</td>",
            "bottom" => "... {totalSales}</td>", 

If you need anything different from this, let us know the detail.

iWorQ Systems commented on Nov 21, 2024

There are a couple of issues I am seeing.

First, I have spaces in my column names and that is causing this error.

This error is when I try to Use the column Permit # to do the calculation.

Second, When I do use a column that has no space it works, however not all my rows have data and when it does the sum it is returning a NaN rather than the actual Number.

My guess is that the Sum is not converting Nulls to 0 AND so it is failing. Is there anything I can do on my end (I still need to display nulls as they are) to fix this issue?

iWorQ Systems commented on Nov 21, 2024

I did This to koolreport/datagrid/DataTables.php and it worked for the NaN issue.

Not sure that really helps or not.

Sebastian Morales commented on Nov 22, 2024

Thank you for your detail feedback and suggestion. We will fix these two issues in the next version of datagrid/DataTables.

iWorQ Systems commented on Nov 22, 2024

Do you have an ETA on when that would be done?

Sebastian Morales commented on Nov 25, 2024

Pls send us an email to support@koolreport.com and mention this topic. We will send you a development version of datagrid/DataTables widget to fix this issue.

iWorQ Systems commented on Sep 22

I know that is has been forever since this thread and I am finally getting back to this. So it fixes the first issue of the JS error. but this file did not fix the second issue of NAN issue.

Also, not sure, but if a group by goes to another page does it only calculate for the group by on the one page or the full group by?

Sebastian Morales commented 6 days ago

Regarding the Not a Number issue, we are not sure whether forcefully convert a NaN value into 0 for group aggregation or let users specifically convert the NaN value is the best strategy yet.

For the group aggregated value I can confirm it only aggregates grouped rows of the current page if paging is enabled. Do you need an option that aggregates grouped rows across multiple pages?

iWorQ Systems commented 6 days ago

it would be helpful to have all the same grouped categories have the total at the end of the of their group by. we do 100 rows per page but have some groups that exceed that.

We will look into how we can get the summed values to not be NAN.

Sebastian Morales commented 5 days ago

We will find a solution for group aggregates across multiple pages as an option for DataTables' row group and let you know the result soon.

Sebastian Morales commented 1 day ago

We have added an option for DataTables' row group aggregates to work across multiple pages beside the current current page only default option. If you want to try it pls send an email to support@koolreport.com and mention this topic. Rgds,

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