Display Status image on CGridView column

You are viewing revision #6 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#5)

How to display status image on admin gridview.

First you can create the UtilityHtml.php file in componet folder. (Otherwise which call a common file)

Put the below function in UtilityHtml.php file:

public static function getImagetitle($status) {
    if ($status == 1 || strtolower($status) == 'yes') {
        return 'Active';
    } else {
        return 'Inactive';

public static function getStatusImage($status) {
    if ($status == 1 || strtolower($status) == 'yes') {
        return Yii::app()->request->baseUrl . '/images/checked.png';
    } else {
        return Yii::app()->request->baseUrl . '/images/unchecked.png';

and display the grid view on admin.php file

    'filter'=>array('1'=>'Active', '0'=>'Inactive'),
    'value'=>'CHtml::tag("div", array(
            "style"=>"text-align: center",
        CHtml::tag("img", array(
            "title"=>UtilityHtml::getImagetitle(GxHtml::valueEx($data, "is_active")),
            "src"=>UtilityHtml::getStatusImage(GxHtml::valueEx($data, "is_active")),