title: Add dynamic css class to every row/cell in CGridView
body: <p>I'm a student and working on my practical project. Its a web application which tracks google rankings for keywords and shows them as a table. Now I want to color every row green, if the current ranking is better than the previous, red if the ranking went down etc. How can I implement this in Yii with CGridView? Currently I have the following solution. In the ControllerClass I have a function </p>
  
  <pre><code>public function getCssClass($data)
  {
      $cssClass;
  
      if('($data-&gt;current_pos&gt;$data-&gt;prev_pos) || ($data-&gt;current_pos===null &amp;&amp; $data-&gt;prev_pos!==null)')
      {
          $cssClass='rdown';
      }
      elseif('$data-&gt;current_pos&lt;$data-&gt;prev_pos')
      {
          $cssClass='rup';
      }
      else
      {
          $cssClass='requal';
      }
  
      return $cssClass;
  }
  </code></pre>
  
  <p>And in the view I call this function at 'rowCssClassExpression':</p>
  
  <pre><code>&lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array(
  'id'=&gt;'keyword-grid',
  'dataProvider'=&gt;$keywordDataProvider,
  'rowCssClassExpression' =&gt; $this-&gt;getCssClass($data),
  'columns'=&gt;array(
      'keyword_name',
      array(
          'name'=&gt;'current_pos',
          'htmlOptions'=&gt;array('style'=&gt;'text-align: center'),
      ),
      array(
          'name'=&gt;'prev_pos',
          'htmlOptions'=&gt;array('style'=&gt;'text-align: center'),
      ),
      array(
          'name'=&gt;'top_pos',
          'htmlOptions'=&gt;array('style'=&gt;'text-align: center'),
      ),
      'url',
      array(
          'class'=&gt;'CButtonColumn',
          'template'=&gt;'{view}{delete}',
          'viewButtonUrl'=&gt;'Yii::app()-&gt;createUrl("/keyword/view", array("id"=&gt;$data-&gt;id))',
          'deleteButtonUrl'=&gt;'Yii::app()-&gt;createUrl("/keyword/delete", array("id"=&gt;$data-&gt;id))',
      ),
  ),
  'nullDisplay'=&gt;'-',
  )); ?&gt;
  </code></pre>
  
  <p>This is my table:</p>
  
  <p>Keyword current previous</p>
  
  <p>Keyword1   7       7</p>
  
  <p>Keyword2   8       10</p>
  
  <p>Keyword3   26      20</p>
  
  <p>But the html result is that every row gets the class 'rdown'. I can't find my mistake :-( If someone could help and point me in the right direction I would really appreciate it. </p>