2016-03-01 117 views
0

如何在GridView中合併一列或多列?組合/合併列Yii2 Gridview

我目前使用Kartikv Gridview,但不想創建一個額外的頁腳/標題。

與正常的表,這將與合併單元格來實現

我想只是「OD」與右邊的4列合併下面的「OD」,在第2列居中

grdiview

當前的GridView:

<?= GridView::widget([ 
    'dataProvider'=> $fixtures, 
    'columns' => [ 
     [ 
      'header' => 'Match Date', 
      'value' => function($data){ 
       return date("d M Y", strtotime($data['fixtureDate'])); 
      } 
     ], 
     [ 
      'header' => 'Home/Away', 
      'value' => function($data){ 
       return $data['homeAway'] 
      } 
     ], 
     [ 
      'contentOptions' => function($data){ 
       return $style['class']; 
      }, 
      'value' => function($data){ 
       if($data['homeAway'] == 1 || $data['homeAway'] == 0){ 
        return $data['homeScore']; 
       } 
      }, 
     ], 
     [ 
      'value' => function(){ 
       return 'vs';  
      } 
     ], 
     [ 
      'value' => function($data){ 
       return $data['awayScore']; 
      } 
     ], 
     [ 
      'header' => 'Against', 
      'value' => function($data){ 
       return $data['awayTeamName']; 
      } 
     ] 
    ], 
    'summary' => false, 
    'responsive'=>true, 
    'hover'=>true 
]); ?> 
+0

請出示你的GridView代碼.. – scaisEdge

+0

任何人都得到一個答案,這一次請 – makie

+0

我已經張貼解答希望是有用 – scaisEdge

回答

0

可能是你需要這個

<?= GridView::widget([ 
    'dataProvider'=> $fixtures, 
    'columns' => [ 
     [ 
      'header' => 'Match Date', 
      'value' => function($data){ 
       return date("d M Y", strtotime($data['fixtureDate'])); 
      } 
     ], 
     [ 
      'header' => 'Home/Away', 
      'value' => function($data){ 
       return $data['homeAway'] 
      } 
     ], 
     [ 
      'header' => 'Home/Away', 
      'value' => function($model){ 

      if($model->homeAway == 1 || $model->homeAway == 0){ 
        return $model->homeAway . ' ' . $model->homeScore . ' vs ' . $model->awayScore . ' ' . $model->awayTeamName; 
       } else { 
        return $model->homeAway . ' ' . ' vs ' . $model->awayScore . ' ' . $model->awayTeamName; 
       } 
      } 
     ],  

    ], 
    'summary' => false, 
    'responsive'=>true, 
    'hover'=>true 
]); ?> 
+0

感謝您的,但這隻會在一個小區創建內容並沒有真正合並單元格狀當在html中使用colspan – makie

+0

然後你只想在頭文件中使用colspan? – scaisEdge

+0

不是。網格需要保持原樣,但OD或杯匹配的地方跨過5個單元格的行中的單元格 – makie