Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YII2 add colspan in gridview header

How to add a colspan in a header in gridview??

Normally a header looks like this...

<table class="table">
        <thead>
            <tr>
              <th>Header1</th>
              <th>Header2</th>
              <th>Header3</th>
              <th>Header4</th>
              <th>HeaderA1</th>
              <th>HeaderA2</th>
              <th>HeaderA3</th>
              <th>HeaderB1</th>
              <th>HeaderB2</th>
              <th>HeaderB3</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>body1</td>
                <td>body2</td>
                <td>body3</td>
                <td>body4</td>
                <td>body5</td>
                <td>body6</td>
                <td>body7</td>
                <td>body8</td>
                <td>body9</td>
                <td>body10</td>
            </tr>
        </tbody>
    </table>

enter image description here

I want to make it look like this...

<table class="table">
        <thead>
            <tr>
              <th rowspan=2>Header1</th>
              <th rowspan=2>Header2</th>
              <th rowspan=2>Header3</th>
              <th rowspan=2>Header4</th>
                <th colspan=3>Header A</th>
                <th colspan=3>Header B</th>
            </tr>
            <tr>

              <th>A1</th>
              <th>A2</th>
              <th>A3</th>
              <th>B1</th>
              <th>B2</th>
              <th>B3</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>body1</td>
                <td>body2</td>
                <td>body3</td>
                <td>body4</td>
                <td>body5</td>
                <td>body6</td>
                <td>body7</td>
                <td>body8</td>
                <td>body9</td>
                <td>body10</td>
            </tr>
        </tbody>
    </table>

enter image description here

like image 395
beginner Avatar asked Dec 19 '22 04:12

beginner


1 Answers

To add a colspan in a table's header you should insert attribute colspan to headerOptions of the column:

'headerOptions' => [
    'colspan' => '2',
]

For the next column you should hide it's header with:

'headerOptions' => [
    'style' => 'display: none;',
]
like image 166
Wierus Avatar answered Dec 30 '22 22:12

Wierus