Aditya Dharma Aditya Dharma - 1 year ago 245
PHP Question

Set width image in gridview yii2

how to set width image in gridview widget in yii2?

I've been using this method to display the image.
Image in gridview in yii2

Answer Source

You can define class for cells as in example

    'attribute' => 'title',
    'format' => 'image',
    'value' => function($data) { return 'you_image.jpeg'; },
    'contentOptions' => ['class' => 'come-class']

Then set image width using css. If image width can be different, use html format

    'attribute' => 'title',
    'format' => 'html',
    'value' => function($data) { return Html::img('you_image.jpeg', ['width'=>'100']); },
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download