【问题标题】:how can i set an event on custom button in actionColumn of gridView in yii?如何在 yii 的 gridView 的 actionColumn 中的自定义按钮上设置事件?
【发布时间】:2018-01-03 18:00:34
【问题描述】:

我的 yii 项目中有这个 gridview 代码,我想在用户单击“更改”按钮时调用下一个视图,请帮我解决这个问题。我已经搜索过,但无法获得全面的解决方案。

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'name',
        'address:ntext',
        'banner_a4',
        'added_by',
        // 'ts',


        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{view} {update} {delete} {change}',
            'buttons' => [
                'change' => function ($url,$model,$key) {
                        return Html::a('Change', $url);
                },
            ],

        ],


    ],

]); ?>

【问题讨论】:

  • 还有你的问题吗?

标签: javascript php html gridview yii2


【解决方案1】:

也许你不知道如何设置 URL,看看这个。

'class' => 'yii\grid\ActionColumn',
     'template' => '{view} {change}',
                'buttons' => [


        'change' => function ($url, $model, $key) {
             $options = ['target' => '_blank',];
             return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', Url::to(['/your-controller/nextview','id'=>$model->id]), $options);
        },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    相关资源
    最近更新 更多