H
H
hollanditkzn2017-03-22 18:43:27
Yii
hollanditkzn, 2017-03-22 18:43:27

How to add new tags to table in gridView?

I have a code in the gridView, but using the example https://dev-tips.ru/blog/post/gridview-v-yii2-pros... two options were indicated as yes and no, I converted them a bit and got me this code

[
                'attribute' => 'status',
                'format' => 'raw',
                'value' => function($model, $key, $index, $column){
                    $active = $model->{$column->attribute} == 0;
                    return Html::tag(
                        'div',
                        $active ? 'Новый' : 'В работе',
                        [
                            'class' => 'label label-'.($active ? 'primary' : 'success'),
                        ]
                    );      
                },
                'headerOptions' => ['width' => '50'],
            ],

But I need not 2 parameters, but about 9 tags.
I tried to do it through swich
switch ($status) {
                        case '0':
                            'Новый'
                            break;
                    }

But then I caught up that it wouldn’t work like that, and here I how to assign several tags?
Or is it easier to do it with jquery?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-03-22
@hollanditkzn

Good evening.
In the model, you create a public, static method, where you prescribe all nine parameters.
In gridview call this method and get dropdown list

O
Oboronitel, 2017-12-27
@Oboronitel

Hello.
Try adding format='raw' to the hollow.
This will display the tags.
He gave an example below:

...
            'columns' => [
                [
                    'attribute' => 'id',
                    'value' => 'id',
                    'contentOptions' => ['width' => '20px'],
                ],
                [
                    'attribute' => 'name',
                    'format' => 'raw',
                    'value' => function ($data) {
                        $fieldValue = '<strong>'.$data->name.'</strong>';
                        return $fieldValue;
                    },
                    'contentOptions' => ['width' => '150px'],
                ],
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question