Set width image in gridview yii2

前端 未结 3 672
情书的邮戳
情书的邮戳 2021-02-15 16:49

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

相关标签:
3条回答
  • 2021-02-15 16:56

    Use:

    'value' => function($data) {
            return Html::img($data->imageurl,['width'=>100]);
       },
    

    And in your model:

      /*
        Return Image url path
      */
       public function getimageurl()
       {
          // return your image url here
          return \Yii::$app->request->BaseUrl.'/uploads/'.$this->ImagePath;
       }
    
    0 讨论(0)
  • 2021-02-15 16:57

    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']); },
    ],
    
    0 讨论(0)
  • 2021-02-15 17:09

    Use

    'format' => ['image',['width'=>'100','height'=>'100']],
    

    example:

    [           
          'attribute' => 'image',
          'format' => ['image',['width'=>'100','height'=>'100']],
          'value' => function($dataProvider) { return $dataProvide->image; },
    
    
    ],
    
    0 讨论(0)
提交回复
热议问题