Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ran into a similar problem however as our CSS is for a legacy system I didn't want to roll in yet more CSS rules. In addition I needed support for extra things such as targeting the header with a specific CSS class on the table row and putting in first/last css classes on the items.</p> <p>To achieve a first/last css on the items you do not need to extend the GridView and can use the handy rowCssClassExpression parameter.</p> <p>To achieve my second objective of injecting a CSS class into the 'table thead tr' element I did have to override the renderTableHeader() method.</p> <p>I strongly advise you only consider this route as a last resort because if you update the version of Yii it is conceivable that they make changes that are not backwards compatible with the renderTableHeader() method. Alternatively you could write a test case that runs your widget through a DOM checker to confirm that you only have 1 table element, 1 thead element, 1 tbody element etc... </p> <p> <pre><code>Yii::import('zii.widgets.grid.CGridView'); class FXSGridView extends CGridView { public $headerCssClass = 'columnHeadings'; public $itemsCssClass = 'grey'; public $rowCssClassExpression = '$this-&gt;rowCssClassFunction($row, $data);'; public $rowCssClass = array('odd','even'); public function rowCssClassFunction($row, $data) { $classes = array(); if ($row == 0) $classes []= 'first'; if ($row == $this-&gt;dataProvider-&gt;getItemCount() - 1) $classes []= 'last'; // Do flip/flop on defined rowCssClass if(is_array($this-&gt;rowCssClass) &amp;&amp; !empty($this-&gt;rowCssClass)) $classes []= $this-&gt;rowCssClass[$row % count($this-&gt;rowCssClass)]; return empty($classes) ? false : implode(' ', $classes); } public function renderTableHeader() { if(!$this-&gt;hideHeader) { echo "&lt;thead&gt;\n"; if($this-&gt;filterPosition===self::FILTER_POS_HEADER) $this-&gt;renderFilter(); echo '&lt;tr class="' . $this-&gt;headerCssClass . ' "&gt;' . "\n"; foreach($this-&gt;columns as $column) $column-&gt;renderHeaderCell(); echo "&lt;/tr&gt;\n"; if($this-&gt;filterPosition===self::FILTER_POS_BODY) $this-&gt;renderFilter(); echo "&lt;/thead&gt;\n"; } else if($this-&gt;filter!==null &amp;&amp; ($this-&gt;filterPosition===self::FILTER_POS_HEADER || $this-&gt;filterPosition===self::FILTER_POS_BODY)) { echo "&lt;thead&gt;\n"; $this-&gt;renderFilter(); echo "&lt;/thead&gt;\n"; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload