Y
Y
yura_born2020-02-17 10:38:10
Yii
yura_born, 2020-02-17 10:38:10

How to add your ID to ActionColumn?

I am using SQLDataProvider and GridView.
Inserted into GridView:

'columns' => [
    // ...
    [
        'class' => ActionColumn::className(),
    ],
]


buttons appeared, but the button leads to a link for example: site.ru/index.php?r=sotrudniki/view&id=1.
but in my sotrudniki table, the code field is used instead of id, and as far as I understand, the record number is inserted into the id of the button, because transition using pagination, on a new line the first entry again has id=0.
How to customize ActionColumn ? Does anyone have any examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-02-17
@yura_born

'columns' => [
    // ...
    [
        'class' => ActionColumn::className(),
        'buttons' => [
            'view' => function($url, $model, $key){
                return Html::a('View', ['sotrudniki/view', 'code' => $model->id);
            }
        ]
    ],
]

Bring it to working condition yourself.

Y
yura_born, 2020-02-17
@yura_born

Did it like this:

[
                        'class' => ActionColumn::className(),
                        'buttons'=>[
                            'view' => function ($url, $model, $key) {
                                return Html::a('View',['sotrudniki/view','id'=>$model['code']]);
                            },
                        ],
                        'header' =>'Действия с записью',
                    ],

maybe it will be useful for someone

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question