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

2
  • 1
    See if it helps: stackoverflow.com/a/29791573/2559712 Commented Mar 2, 2016 at 11:26
  • Thank you but this is not what i need to accomplish. @ıɹnʇɐɹʇıʞuɐ Commented Mar 3, 2016 at 1:16

1 Answer 1

2

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']],
        ],
    ]
],
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.