3

I am using gridview to list all my data. my table looks like this.

<?= GridView::widget([
    'dataProvider' => $dataProvider,  
    'columns' => [
        'firstName',
        'lastName',
        'startDate',
        'hiredDate'
    ],
]) ?>

which renders a table like this.

enter image description here

how can i add another header for grouping NAME and DATE so that it will look like this. like rowspan in pure HTML.

enter image description here

ii--L--ii
  • 207
  • 1
  • 7
  • 23

1 Answers1

1

Use https://github.com/kartik-v/yii2-grid extension

<?= GridView::widget([
'beforeHeader' => [
    [
        'columns' => [
            ['content' => 'Name', 'options' => ['colspan' => 2, 'class' => 'text-center warning']],
            ['content' => 'Date', 'options' => ['colspan' => 2, 'class' => 'text-center warning']],
        ],
    ]
],
GeZo
  • 86
  • 2
  • 4
  • In addition to whom want to group header cells vertically: use 'afterHeader' method instead of 'beforeHeader': in gridView columns you manage first row cells with rowspan options and in afterHeader columns you manage second row cells. – Scilef May 21 '20 at 13:28