GridView row as link, except action column items in Yii2

后端 未结 8 2013
忘了有多久
忘了有多久 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 07:10

    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.

    0 讨论(0)
  • 2021-01-02 07:19

    User 'filterPosition'=>' ',

    <?=
                        GridView::widget([
                            'dataProvider' => $dataProvider,
                            'filterModel' => $searchModel,
                            'resizableColumns' => true,
                            'containerOptions' => ['style' => 'overflow: auto'], // only set when $responsive = false
                            'headerRowOptions' => ['class' => 'kartik-sheet-style'],
                            'filterRowOptions' => ['class' => 'kartik-sheet-style'],
                            'pjax' => true,
                            'hover' => true,
                            'export' => false,
                            'columns' => $gridColumns,
                            'filterPosition'=>' ',
                        ]);
                        ?>
    
    0 讨论(0)
提交回复
热议问题