yose
yose

Reputation: 109

YII2 - How to merge row yii2 gridview?

i have gridview table like this : Gridview Storelist

i want to merge store 1(example) with 4 row detail information. is it possible to do it with? i have a code in gridview :

<?php Pjax::begin(['id' => 'pjax_filesetting','timeout'=>false]) ?>
<?php 

    $this->registerJs(
    "
        $('.btneditfile').click(function(){
            var hqid = $(this).attr('data-hqid');
            var storeid = $(this).attr('data-storeid');
            var filename = $(this).attr('data-filename');

        location.href = '/pos/editfilesetting?hqid='+hqid+'&storeid='+storeid+'&filename='+filename;
            return false;
            });
    ");
?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'options' => ['class' => 'grid-view active-table'],
        'columns' => 
            [
                ['class' => 'yii\grid\SerialColumn'],
                [
                    'label' => 'Store Name',
                    'attribute' => 'store_name',
                    'encodeLabel' => false,
                ],
                [
                    'label' => 'Filename',
                    'attribute' => 'filename',
                    'encodeLabel' => false,
                ],
                [
                    'label' => 'Datecheck',
                    'attribute' => 'datecheck',
                    'encodeLabel' => false,
                    'value' => function($model){

                                $datecheck = $model["datecheck"];

                                if($datecheck)
                                {
                                    return $model["datecheck"] = "Check";
                                }
                                else
                                {
                                    return $model["datecheck"] = "Not Check";

                                }
                        }
                ],
                [
                    'label' => 'Timecheck',
                    'attribute' => 'timecheck',
                    'encodeLabel' => false,
                    'value' => function($model){

                                $timecheck = $model["timecheck"];

                                if($timecheck)
                                {
                                    return $model["timecheck"] = "Check";
                                }
                                else
                                {
                                    return $model["timecheck"] = "Not Check";

                                }
                           }
                ],
                [
                    'label' => 'Maintenance code',
                    'attribute' => 'maincode',
                    'encodeLabel' => false,
                ],
                [
                    'label' => 'Final Filename',
                    'attribute' => 'usedfilename',
                    'encodeLabel' => false,
                ],
                [
                    'class' => 'yii\grid\ActionColumn',
                    'template' => '<div align="center">{update} {delete}</div>',
                            'buttons' => [                    
                                'update' => function ($url, $model) use ($controller) {
                                    return Html::button(
                                        '<span class="glyphicon glyphicon-pencil"></span>',
                                        [
                                        'class' => 'btn btn-primary btn-xs btneditfile',
                                        'title' => Yii::t( $controller->transmodule, 'Edit' ),
                                        'style' => ['padding-top' => '5px', 'padding-bottom' => '5px'],
                                        'id' => 'editfile',
                                        'data-storeid' => $model['id'],
                                        'data-hqid' => $model['cmshqid'],
                                        'data-filename' => $model['filename'] 
                                    ]
                                );
                            },

                            'delete' => function ($url, $model)use ($controller){   
                                return Html::button(
                                '<span class="glyphicon glyphicon-trash"></span>',
                                [
                                    'class' => 'btn btn-danger btn-xs btndeletefile',
                                    'title' => Yii::t( $controller->transmodule, 'Delete' ),
                                    'style' => ['padding-top' => '5px', 'padding-bottom' => '5px'],
                                    'data-storeid' => $model['id'],
                                    'data-hqid' => $model['cmshqid'],
                                    'data-filename' => $model['filename'] 
                                ]
                            );
                        },        
                    ],
                ]
            ],
    ]) ?>
    <?php Pjax::end() ?>

what must i do to merge it? what i need is if the store name is same, merge it column .

Upvotes: 0

Views: 1480

Answers (1)

raditz farhan
raditz farhan

Reputation: 177

Is the store and other details in one table or separate table? If it is in separate tables, the $dataProvider should query from the store table. In the store model create a hasMany relation to the other table which contain the details. So in the view, in the gridview column function you can loop through those values and display it in the same row.

Upvotes: 1

Related Questions