Jump to content
Larry Ullman's Book Forums

Cgridview : How Can I Customize Text In Cells On The Fly


Recommended Posts


I am using a CGridView with a CSqlDataProvider.


I would like to dynamically change the text displayed in the cells for some columns.

For instance:

- instead of displaying a name, I would like to display a link

- if a certain value is present, display this value in red


I mean I want to put HTML in my cells and expect this HTML to be parsed and rendered by the browser.

I don't want to change the class of the underlying <tr>, <td>...


For so doing I put some expressions in the 'columns' array:

'columns' => array(    'phase',
                                  array( 'name' => 'version',
                                            'value' => "preg_replace('/($today.+)/','<span style=\'color: red;\'>\$1</span>', \$data['version'])"
                                          ) ,
                                  array( 'name' => 'deadline',
                                  'value' => '"<a href=\'candidateRelease/view/id/\$data[\'id\']\'>\$data[\'deadline\']</a>)"'
                                          ) ,


Expression seems to be evaluated correctly but the text rendered in the cell shows the html tags (as if the result of the evaluation had gone through a call to htmlentities().


Does someone know how I could change this ?


Thanks and regards.

Edited by jerome.celle@gmail.com
Link to comment
Share on other sites

Answer found after some reading...

In fact widgets are not really homogeneous...

For CGridView you must specify the html type like this:


array( 'name' => 'version',
          'value' => "preg_replace('/($today.+)/','<span style=\'color: red;\'>\$1</span>', \$data['version'])",

          'type' => 'html' 

        ) ,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...