Run AJAX command from Gridview html anchor link?

Hi,

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,

U4EA

Hi, try this code


'columns' => [

        'name',

        [

            'attribute'=>'name',


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

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

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

            },

           

            'format'=>'raw'

        ],

        

    ],




<script>

$(function(){

$('.doajax').click(function(){

////do ajax here

})

})

</script>



Thank you. I will give that a try…