使gridview的actioncolumn的图标不再换行

使gridview的actioncolumn的图标不再换行

解决了一个很小的大问题,很好

刚开张了一个公众号

先交待,参考资料在这里:prevent-gridview-actioncolumn-icons-from-wrapping-globally

1、先建一个文件container.php,内容如下:

    <?php
    \Yii::$container->set('yii\grid\ActionColumn', [
            // 'contentOptions' => ['width' => '80px;'],
            'contentOptions' => ['style' => ['white-space' => 'nowrap']],
    ]);
说明:第一句是直接定义宽度为80px,但默认好像就是这80px,应该是没用。
第二句是说不换行,这个应该可以,所以我用的是这个。

2、再把container.php添加到项目中去

    require_once(__DIR__ . '/container.php');

资料原文复制在这里:

You should create file “container.php” in config folder. And put this code

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

Then, You should include this file in your “web/index.php”. Like that

    <?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();

Building on top of @vitalik_74’s answer, I added the nowrap style for that column instead of the width.

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

刚发现这里还有一个回答,内容一样,但更简洁。

You can use Yii::$container->set().
For example:

    // add following line in config/web.php and config/console.php
    require __DIR__ . '/container.php';
    // creates a config/container.php file and add following
    \Yii::$container->set('yii\grid\GridView', [
        'tableOptions' => [
            'class' => 'table table-condensed',
        ],
    ]);

For more information: Dependency Injection Container and Practical Usage
这个连接的地址在这里: how-do-i-set-a-default-configuration-for-gridview-in-yii2-without-the-widget-fac


涉及到的YII2文档在这里

http://www.yiiframework.com/doc-2.0/guide-concept-di-container.html#practical-usage

刚开张了一个公众号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值