2017-02-17 69 views
0

我有這樣的gridview表: Gridview StorelistYII2 - 如何合併行yii2 gridview?

我想合併存儲1(示例)與4行詳細信息。有可能做到這一點嗎? 我有一個代碼在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() ?> 

我必須做些什麼來合併呢? 我需要的是如果商店名稱相同,則合併它的列。

回答

1

商店和其他細節在一張桌子或單獨的桌子?如果它在單獨的表中,$ dataProvider應該從商店表中查詢。在商店模型中,創建與包含詳細信息的其他表的hasMany關係。所以在視圖中,在gridview列函數中,您可以遍歷這些值並將其顯示在同一行中。