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.

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

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败