dongping4901 2017-02-17 06:35
浏览 160
已采纳

YII2 - 如何合并行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 .

  • 写回答

1条回答 默认 最新

  • douyan1903 2017-02-17 09:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目