Jump to content



Photo

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

cgridview evaluate

  • Please log in to reply
2 replies to this topic

#1 jerome.celle@gmail.com

jerome.celle@gmail.com

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 4 April 2017 - 8:01 AM

Hello,

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',
                                  'app',
                                  array( 'name' => 'version',
                                            'value' => "preg_replace('/($today.+)/','<span style=\'color: red;\'>\$1</span>', \$data['version'])"
                                          ) ,
                                  'comment',
                                  'nb',
                                  array( 'name' => 'deadline',
                                  'value' => '"<a href=\'candidateRelease/view/id/\$data[\'id\']\'>\$data[\'deadline\']</a>)"'
                                          ) ,
                                  'status'
                            ),

 

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, 4 April 2017 - 8:05 AM.

  • 0

#2 jerome.celle@gmail.com

jerome.celle@gmail.com

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 4 April 2017 - 9:52 AM

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' 

        ) ,


  • 0

#3 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4749 posts
  • LocationState College, PA (USA)

Posted 10 April 2017 - 10:06 PM

Thanks for sharing what you learned! Much appreciated (and kudos for figuring it out)!


  • 0





Also tagged with one or more of these keywords: cgridview, evaluate