Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Gridview Adding another Header

Tags:

gridview

yii2

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

like image 754
ii--L--ii Avatar asked Jun 03 '26 10:06

ii--L--ii


1 Answers

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']],
        ],
    ]
],
like image 172
GeZo Avatar answered Jun 06 '26 05:06

GeZo