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

Revision #5 has been created by softark on Jul 23, 2013, 3:38:10 PM with the memo:

Reformatted the code for better readability.
« previous (#4) next (#6) »

Changes

Title unchanged

Display Status image on CGridView column

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Status, admin, CGridView, gridview, image

Content changed

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) pPut the below function in UtilityHtml.php file:
 
```php public static function getImagetitle($status) {     if if ($status == 1 || strtolower($status) == 1'yes') {      return 'Active';      } else if ($status == 0) {
 
    
{
 
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
 
 
```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", array(
 
           
"title"=>UtilityHtml::getImagetitle(GxHtml::valueEx($data, \'"is_active\'")),
 
            
"src" => UtilityHtml::getStatusImage(GxHtml::valueEx($data, \'"is_active\')))))'")), ))
 
    )',
 
'htmlOptions' => array('width'=>"80px") ),
 
```
0 0
5 followers
Viewed: 21 199 times
Version: 1.1
Category: Tutorials
Written by: Ankit Modi
Last updated by: samdark
Created on: Jul 22, 2013
Last updated: 5 years ago
Update Article

Revisions

View all history