gridview - Add dynamic css class to every row/cell in CGridView -


I am a student and working on my practical project. This is a web application that tracks Google rankings for keywords and shows them as a table. Now I want a green color for every line, if the current ranking is better than the previous, red, then the ranking goes down. e.t.c. How can I apply it to CGI in Yii? Currently I have the following solution I have a function in the ControllerClass

  public function getCssClass ($ data) {$ cssClass; If ('($ data-> current_posy> $ data- & gt; prev_pos) || ($ data- & gt; current_poz === blank & amp; $ data-> gt; prev_pos! == tap ) ') {$ CssClass =' ​​rdown '; } Elseif ('$ data- & gt; current_page & lt; $ data- & gt; prev_pos') {$ cssClass = 'rup'; } And {$ cssClass = 'requal'; } Return $ cssClass; }   

And in the view I call this function on 'rowCssClassExpression':

   $ keywordDataProvider , 'RowCssClassExpression' = & gt; $ the- & gt; array ('keyword_name', array ('name' = & gt; 'current_pos', 'html_ops' = & gt; array ('style' => Text-align: center '),), array (' name '= & gt; prev_pos', 'htmlOptions' = & gt; array ('style' = & gt; 'text-align: center'), ), Array ('name' = & gt; 'top_pos',' html_Options' = & gt; array ('style' = & gt; 'text-align: center'),), 'url', array ('class '= & Gt; CBTToncolm', 'Template' = & gt; '{view} {delete}', 'ViewButtonUrl' = & gt; Yii :: app () - & gt; cre AteUrl ("/ keyword / view", array ("id ="> $ data-> ID)), 'deleteButtonUrl' = & gt; 'Yii :: app () - & gt; createUrl ("/" , 'NullDisplay' = & gt; '-',));? & Gt;   Pre> 

This is my table:

Keyword Existing Previous

Keyword 1 7 7

Keyword 2 8 10

Keywords 3 26 20

But the HTML result is that every line class becomes 'rdown'. I can not find my fault :-( If someone can help me in the right direction I would appreciate it I am

'($ data- & gt; current_poz> $ data- & gt; Prev_pos) || ($ Data-> current_poz === faucet & amp; $ data-> prev_pos! = Null) is a string in its system and it is always true That's the reason that rdown is back. ' to wrap the situation?

Please also keep in mind that there is a PHP expression, perhaps the result of your method should be wrapped in quotes:

  'rowCssClassExpression' = & gt; unfortunately this installation of the model Will also not work because of  $ data  "$."  rowCssClassExpression  is defined (and evaluated for each line of the grid) but not in the context of your view.  

As a solution, you will see ion as a method of getCssClass as your model: 'rowCssClassExpression ='> ' $ Data- & gt; You can also see the CGridColumn class to specify a CSS class for each particular cell. GetCssClass () ',



Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -