kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
557 stars 303 forks source link

groupFooter.content.GridView::F_SUM prints "f_sum" #1058

Open maxxer opened 1 year ago

maxxer commented 1 year ago

Prerequisites

Steps to reproduce the issue

echo GridView::widget([
    'filterModel' => $searchModel,
    'dataProvider' => $dataProvider,
    'columns' => [
        [
            'attribute' => 'company',
            'group' => true,
            'groupFooter' => function ($model, $key, $index, $widget) {
                return [
                    'mergeColumns' => [[0, 1, 2]],
                    'contentOptions' => [
                        0 => ['style' => 'font-weight: bold;'],
                        3 => ['style' => 'text-align: right;'],
                    ],
                    'content' => [
                        0 => $model['company'],
                        3 => GridView::F_SUM,
                    ],
                ];
            },
        ],
        'title',
        [
            'attribute' => 'start_time',
            'format' => 'dateTime',
            'hAlign' => 'right',
        ],
        [
            'attribute' => 'tracking_minutes',
            'format' => 'duration',
            'hAlign' => 'right',
        ],
    ],
]);

Expected behavior and actual behavior

immagine

I don't know if it matters, the ActiveDataProvider query comes from a (new Query) and not from an AR find()

Environment

Browsers

Operating System

Libraries

Isolating the problem

maxxer commented 1 year ago

A friend appointed me the F_SUM feature works in javascript, so with plain integer/float values. I tied removing the format option from all columns, but still won't sum

kartik-v commented 1 year ago

Yes the F_SUM (means a numeric summation) and needs a numeric value in each cell in the specific Grid DataColumn for summary to be mathematically possible. You need to ensure that the DataColumn value is numeric and you can use the DataColumn content property to format the data content for display.