dongping4901 2017-02-16 22: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 01: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 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack