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 12 hours ago - 1 comments

iWorQ Systems commented 12 hours ago

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 3 hours ago

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.

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