GridView row as link, except action column items in Yii2

后端 未结 8 2083
忘了有多久
忘了有多久 2021-01-02 06:20

When i use the below code it overrides the action-column delete/update links.

\'rowOptions\' => function ($model, $key, $index, $grid) {
    return [
             


        
8条回答
  •  忘掉有多难
    2021-01-02 06:53

    Nothing worked for me from these solutions except:

    echo GridView::widget([
       ...
       'rowOptions' => function ($model, $key, $index, $grid) {
            return [
                'style' => "cursor: pointer",
                'myurl' => ['/route','id'=>$model->id],
            ];
        }
        ...
    

    And the Javascript piece:

    $this->registerJs("
        $('tbody tr[myurl]').click(function (e) {
            if ($(e.target).is('td')) {
                window.location.href = $(this).attr('myurl');
            } 
        });
    ");
    

    Don't now why the other solutions did not work but maybe this solution helps someone before wasting time for hours - as in my case :-(

提交回复
热议问题