简体   繁体   中英

yii2 Set default configuration of ActionColumn in GridView

I want to set a default configuration for all my GridViews. I did this as following:

app\\config\\web.php:

require __DIR__ . '/container.php';

app\\config\\container.php:

use yii\helpers\Html;
use yii\helpers\Url;

\Yii::$container->set('yii\grid\GridView', [
    'layout' => "{items}\n{summary}\n{pager}",
    'columns' => [
        [
             'class' => 'yii\grid\ActionColumn',
             'template' => '{edit}{update}',
             'buttons' => [
                'edit' => function ($url, $model) {
                  return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [Url::to(['edit', 'id' => $model->id])]);
                },
             ],

        ],
    ],
]);

the part where I define the layout works fine.

But apparently the part with the ActionColumn doesn't work, because the whole array-index 'columns' gets overwritten by the column-names when I actually use the GridView in a list.

How can I set default settings for ActionColumn for all GridViews?

Try setting the default values for ActionColumn separately:

\Yii::$container->set('yii\grid\ActionColumn', [
    'template' => '{edit}{update}',
    'buttons' => [
        'edit' => function ($url, $model) {
            return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [Url::to(['edit', 'id' => $model->id])]);
        },
    ],
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM