Yii Framework Forum: how to place a picture above attribute name in GridView - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to place a picture above attribute name in GridView [solved]

#1 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 20-April 17
  • Location:Hannover

Posted 03 November 2017 - 02:29 PM

Hi guys,
what I wanna achieve is easy to explain. I want to set a piture in GridView above name of attribute.I have read official documentation here, but i didn't find a way to do it.
Is it possible, and if, how? I try like this,but get error of course

    [
	//show this on screen,above label downstairs        
	Html::img('@web/pictures/tklustig.jpg', ['alt' => 'pic not found', 'class' => 'img-width, 'style' => 'width:100px;height:25px']),
  	'attribute' => 'umkreis',
        'label' => 'Umkreis',
        'value' => function($model) {
            if ($model->umkreis) {
                return $model->umkreis;
            } else {
                return NULL;
            }
        },
        'filterType' => GridView::FILTER_SELECT2,
        'filter' => yii\helpers\ArrayHelper::map(\frontend\modules\bewerber\models\Bewerber::find()->orderBy(['id' => SORT_DESC])->asArray()->all(), 'umkreis', 'umkreis'),
        'filterWidgetOptions' => [
            'pluginOptions' => ['allowClear' => true],
        ],
        'filterInputOptions' => ['placeholder' => 'Radius in Kilometer', 'id' => 'grid-bewerber-search-umkreis'],
        'format' => 'raw',
    ],



Error is like this:
yii\base\UnknownPropertyException: Setting unknown property: kartik\grid\DataColumn::0 in E:\xampp\htdocs\yii2_perswitch\vendor\yiisoft\yii2\base\Object.php:161Stack trace:#0 E:\xampp\htdocs\yii2_perswitch\vendor\yiisoft\yii2\BaseYii.php(529): yii\base\Object->__set('0', '

0

#2 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 10-October 11
  • Location:Russia

Posted 03 November 2017 - 03:02 PM

This
Html::img('@web/pictures/tklustig.jpg', ['alt' => 'pic not found', 'class' => 'img-width, 'style' => 'width:100px;height:25px']),

cause a problem, obviously
0

#3 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 20-April 17
  • Location:Hannover

Posted 04 November 2017 - 02:44 AM

View Postumneeq, on 03 November 2017 - 03:02 PM, said:

This
Html::img('@web/pictures/tklustig.jpg', ['alt' => 'pic not found', 'class' => 'img-width, 'style' => 'width:100px;height:25px']),

cause a problem, obviously

I know.this is reason for error,'cause kartik doesn't accept placing pictures like this. My question is, how to place a picture above label of attribute instead?
0

#4 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 10-October 11
  • Location:Russia

Posted 04 November 2017 - 06:51 AM

[
    ...
    'value' => function($model) {
        $img = Html::img('@web/pictures/tklustig.jpg', ['alt' => 'pic not found', 'class' => 'img-width', 'style' => 'width:100px;height:25px']);
        return $img . ($model->umkreis ?: 'umkreis nicht angegeben');
    },
    ...
],

0

#5 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 20-April 17
  • Location:Hannover

Posted 04 November 2017 - 07:10 AM

View Postumneeq, on 04 November 2017 - 06:51 AM, said:

[
    ...
    'value' => function($model) {
        $img = Html::img('@web/pictures/tklustig.jpg', ['alt' => 'pic not found', 'class' => 'img-width', 'style' => 'width:100px;height:25px']);
        return $img . ($model->umkreis ?: 'umkreis nicht angegeben');
    },
    ...
],


U ardently don't understand,what I want. I want a picture above label of attribute. Coding as U suggest wil constitute picture as attribute. This is already implemented. Look at my attachement,please, in order to understand,what I want. Hope this might succeed,solving my problem. Here is structure of index.php
$gridColumn=[
[ ],
[ ],
.
.
.

];
Pjax::begin();
try {
?>
 <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'filterSelector' => '.choiceRadio',
        'columns' => $gridColumn,
.
.


P.S.: I use GridView of kartik,which is documentated here. Unfortunately, there is no hint solving my problem in this documentation

Attached File(s)

  • Attached File  view.jpg (281.6K)
    Number of downloads: 4

0

#6 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 10-October 11
  • Location:Russia

Posted 04 November 2017 - 08:16 AM

[
    'attribute' => 'blabla',
    'label' => '<img src="/img/main-logo.png" class="logo-img" alt="">blabla',
    'encodeLabel' => false,
],

1

#7 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 20-April 17
  • Location:Hannover

Posted 04 November 2017 - 08:38 AM

View Postumneeq, on 04 November 2017 - 08:16 AM, said:

[
    'attribute' => 'blabla',
    'label' => '<img src="/img/main-logo.png" class="logo-img" alt="">blabla',
    'encodeLabel' => false,
],



Great! Thx a lot for this. U helped me one more time again! That means reputation points for U,of coursePosted Image
This thread can be finished as solved.

Here is complete code:

    [
        'attribute' => 'umkreis',
        'label' => Html::img('@web/pictures/umkreis.jpg', ['alt' => 'pic not found', 'class' => '', 'style' => 'width:100px;height:35px']).'Umkreis',
        'encodeLabel' => false,
        'value' => function($model) {
            if ($model->umkreis) {
                return $model->umkreis;
            } else {
                return NULL;
            }
        },
        'filterType' => GridView::FILTER_SELECT2,
        'filter' => yii\helpers\ArrayHelper::map(\frontend\modules\bewerber\models\Bewerber::find()->orderBy(['id' => SORT_DESC])->asArray()->all(), 'umkreis', 'umkreis'),
        'filterWidgetOptions' => [
            'pluginOptions' => ['allowClear' => true],
        ],
        'filterInputOptions' => ['placeholder' => 'Radius in Kilometer', 'id' => 'grid-bewerber-search-umkreis'],
        'format' => 'raw',
    ],

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users