Difference between #5 and #4 of Display Status image on CGridView column

unchanged
Title
Display Status image on CGridView column
unchanged
Category
Tutorials
unchanged
Tags
Status, admin, CGridView, gridview, image
changed
Content
How to display status image on admingridview.admin
gridview.

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

put the below function in UtilityHtml.php file

Put the below function in UtilityHtml.php file:

~~~
[php]

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

public static function getStatusImage($status) {

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

}
~~~


and display the grid view on admin.php file



~~~
[php]
array(
            'name' => 'is_active',
            'filter' => array('1' => 'Active', '0' => 'Inactive'),
            'type' => 'html',
            'value' => 'CHtml::tag("div", 
array("style"=>"text-align: center" ) ,
CHtml::tag("img",'name'=>'is_active',
    'filter'=>array('1'=>'Active', '0'=>'Inactive'),
    'type'=>'html',
    'value'=>'CHtml::tag("div", array(
"title"=>UtilityHtml::getImagetitle(GxHtml::valueEx($data,
\'is_active\')),"src" =>
UtilityHtml::getStatusImage(GxHtml::valueEx($data, \'is_active\')))))',
            'htmlOptions' => array('width'=>"80px")
            "style"=>"text-align: center",
        ),
        CHtml::tag("img", array(
           
"title"=>UtilityHtml::getImagetitle(GxHtml::valueEx($data,
"is_active")),
           
"src"=>UtilityHtml::getStatusImage(GxHtml::valueEx($data,
"is_active")),
        ))
    )',
    'htmlOptions'=>array('width'=>"80px")
),

~~~