Run AJAX command from Gridview html anchor link?


Have a gridview and I want to add a column to it to that will have a url in it which will run an AJAX command to a URL passing one of the model attributes as a parameter. I was just wondering if there is an easy/programmatic way of doing this in Yii2?

Thanks in advance,


Hi, try this code

'columns' => [




            'value'=>function ($model, $key, $index, $widget) {

                return Html::a($model->name, Url::toRoute(['page/view', 'id' => $model->id]),

					['class' => 'doajax']);










////do ajax here




Thank you. I will give that a try…