kartik-v / yii2-grid

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

pageSummary removed by kv-grid-group.js when grid column is grouped #927

Closed santilin closed 4 years ago

santilin commented 5 years ago

This is a preliminary bug report, if you need a working sample I can do it, but I think the error es pretty easy to reproduce.

When I define a grid with showPageSummary=true and a few columns with pageSummary=true I get a grid with an extra row for the summary columns.

But when I set a column to be grouped: group=true, the summary row dissapears due to this code in kv-grid-group.js:

        adjustLastRow = function () {
        ....
            if ($pageSum.length) {
                $pageSum.find(' > td').each(function () {
                    var $td = $(this);
                    if (!$firstRow.find(' > td[data-col-seq="' + $td.attr('data-col-seq') + '"]').length) {
                         $td.remove();
                    }
                });
            }

If I comment out the $td.remove() line, the summary row stays.

kartik-v commented 5 years ago

Can you please share your gridview and column configuration?

santilin commented 5 years ago

This is the configuration that is not grouped, so the page summary is shown:

<?php
/* @var yii\web\View $this */
/* @var app\models\ExpedienteSearch $searchModel */
/* @var app\models\... $parent */
/* @var array $gridParams */
/* @var array $extraParams */

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\GridView;
use kartik\export\ExportMenu;

$gridColumns = [
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{update} {view} {delete}',
    ],
'codigo' => [ // code
    'attribute' => 'codigo',
],
'destino' => [ // dropdown
    'attribute' => 'destino',
    'group' => false,
    'groupedRow' => false,
    'value' => 'DestinoLabel' ],
'cantidad_ofertada' => [ // NUMBER
    'pageSummary' => true,
    'pageSummaryFunc' => GridView::F_COUNT,
    'attribute' => 'cantidad_ofertada', 
    'format' => 'currency',
    'hAlign' => 'right' ],
'horas_previstas' => [ // NUMBER
    'attribute' => 'horas_previstas', 
    'pageSummary' => true,
    'pageSummaryFunc' => GridView::F_SUM,
    'format' => 'hours',
    'hAlign' => 'right' ],

];
$dataProvider = $searchModel->search($gridParams);

$gridOptions = [
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'showPageSummary' => true,
    'itemLabelSingle' => 'Expediente',
    'itemLabelPlural' => 'Expedientes',

    'pjax' => true,
    'pjaxSettings' => ['options' => ['id' => 'kv-pjax-container-field']],
    'panel' => [
        'type' => GridView::TYPE_PRIMARY,
        'heading' => '<span class="glyphicon glyphicon-book"></span>  ' . Html::encode($this->title)],
    'condensed' => true,
    'hover' => true,

];
?>
<div class='expediente-index'>
<?= GridView::widget( $gridOptions ) ?>
</div><!-- expediente-index -->
<?php

image

And this is the same one with the destino column grouped, that removes the summary row:

<?php
/* @var yii\web\View $this */
/* @var app\models\ExpedienteSearch $searchModel */
/* @var app\models\... $parent */
/* @var array $gridParams */
/* @var array $extraParams */

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\GridView;
use kartik\export\ExportMenu;

$gridColumns = [
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{update} {view} {delete}',
    ],
'codigo' => [ // code
    'attribute' => 'codigo',
],
'destino' => [ // dropdown
    'attribute' => 'destino',
    'group' => true,
    'groupedRow' => true,
    'value' => 'DestinoLabel' ],
'cantidad_ofertada' => [ // NUMBER
    'pageSummary' => true,
    'pageSummaryFunc' => GridView::F_COUNT,
    'attribute' => 'cantidad_ofertada', 
    'format' => 'currency',
    'hAlign' => 'right' ],
'horas_previstas' => [ // NUMBER
    'attribute' => 'horas_previstas', 
    'pageSummary' => true,
    'pageSummaryFunc' => GridView::F_SUM,
    'format' => 'hours',
    'hAlign' => 'right' ],

];
$dataProvider = $searchModel->search($gridParams);

$gridOptions = [
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'showPageSummary' => true,
    'itemLabelSingle' => 'Expediente',
    'itemLabelPlural' => 'Expedientes',

    'pjax' => true,
    'pjaxSettings' => ['options' => ['id' => 'kv-pjax-container-field']],
    'panel' => [
        'type' => GridView::TYPE_PRIMARY,
        'heading' => '<span class="glyphicon glyphicon-book"></span>  ' . Html::encode($this->title)],
    'condensed' => true,
    'hover' => true,

];
?>
<div class='expediente-index'>
<?= GridView::widget( $gridOptions ) ?>
</div><!-- expediente-index -->
<?php

image

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.