防止 GridView ActionColumn 图标全局换行

Prevent GridView ActionColumn icons from wrapping globally

我试图找到答案,但找不到,想知道为什么它是这样设计的:

我的操作栏图标确实一个接一个地换行。

我必须在每个 GridView 中添加这行代码才能在一行中显示图标:

[
    'class' => 'yii\grid\ActionColumn',
    'contentOptions' => ['width' => '80px;'],
],

有没有更好的方法可以在一行中全局显示动作图标?

您应该在配置文件夹中创建文件 "container.php"。并把这段代码

<?php
\Yii::$container->set('yii\grid\ActionColumn', [
        'contentOptions' => ['width' => '80px;'],
]);

然后,您应该将此文件包含在您的 "web/index.php" 中。那样

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

require(__DIR__ . '/../config/container.php');

(new yii\web\Application($config))->run();

就是这样工作 - https://yadi.sk/i/kpgus0eAeeHDw

的基础上,我为该列添加了 nowrap 样式而不是宽度。

\Yii::$container->set('yii\grid\ActionColumn', [
        'contentOptions' => ['style' => ['white-space' => 'nowrap']],
]);