GridView row as link, except action column items in Yii2

I recommend using below javascript to prevent event triggering on filter columns.

<?php
$this->registerJs("
    $('td').click(function (e) {
        var id = $(this).closest('tr').data('id');
        if (e.target == this && id)
            location.href = '" . Url::to(['thread/view']) . "?id=' + id;
    });
");

Or

<?php
$this->registerJs("
    $('tbody td').css('cursor', 'pointer');
    $('tbody td').click(function (e) {
        var id = $(this).closest('tr').data('id');
        if (e.target == this)
            location.href = '" . Url::to(['thread/view']) . "?id=' + id;
    });
");

You could try this. It will make the whole row clickable as long as the user clicks on a td element that is not covered from another element. So also the action column is part of the clickable row, however, not the glyphicons.

<?= GridView::widget([

    ...

    'rowOptions'   => function ($model, $key, $index, $grid) {
        return ['data-id' => $model->id];
    },

    ...

]); ?>

<?php
$this->registerJs("

    $('td').click(function (e) {
        var id = $(this).closest('tr').data('id');
        if(e.target == this)
            location.href = '" . Url::to(['accountinfo/update']) . "?id=' + id;
    });

");

See also documentation for event.target:

The target property can be the element that registered for the event or a descendant of it. It is often useful to compare event.target to this in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.

Tags:

Php

Gridview

Yii2