Question

Is there any way to add other attributes to the image tag generated by TbImageColoumn ?

The documentation is not very clear on how to set image attributes like height, width etc. It only mentions on how to add image src using imagePathExpression attribute,

My current column looks like this

           .....
            array(
                'class'=>'bootstrap.widgets.TbImageColumn',
                'imagePathExpression'=>'$data->getImage("large")',
                'usePlaceKitten'=>false,
                ),
           .....
Was it helpful?

Solution

Digging through the code it seems there is an attribute for setting html attributes to the generated tag using the imageOptions and to set attributes on generated td cell tag we can use the htmlOptions array from the base clase

/**
 * TbImageColumn widget class
 *
 * @package booster.widgets.grids.columns
 */
class TbImageColumn extends CGridColumn
{
    /**
     * @var array the HTML options of the image tag
     */
    public $imageOptions = array();

so to limit image width to 50px the column should be modified to

           .....
            array(
                'class'=>'bootstrap.widgets.TbImageColumn',
                'imagePathExpression'=>'$data->getImage("large")',
                'headerHtmlOptions'=>array('style'=>'min-width: 50px;'),
                'imageOptions'=>array('width'=>'50px'),
                'usePlaceKitten'=>false,
            ),
           .....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top