2015-04-26 54 views
3

如何在gridview標題中添加colspanYII2在gridview標題中添加colspan

通常頭看起來像這樣...

<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

我想使它看起來像這樣...

<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

回答

3

這是如果不擴展和重寫網格視圖小部件,則不可能。 看看Kartik GridView。如果你看看demo,你可以看到它具有你需要的功能。

0

要在表格中的頭添加colspan你應該插入屬性colspan到列的headerOptions

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

對於你應該把它隱藏下一列標題用:

'headerOptions' => [ 
    'style' => 'display: none;', 
]