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 - 6 comments

iWorQ Systems commented on Nov 20

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

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

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

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

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

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

Sebastian Morales commented on Nov 25

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.

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