W
W
wolfcruel972019-03-21 16:28:09
Yii
wolfcruel97, 2019-03-21 16:28:09

How to set global settings for the GridView module in the config?

How to set global settings for the GridView module in the config?
In order not to write in each module:

'pager' => [
                        'firstPageLabel' => false,
                        'lastPageLabel' => false,
                        'prevPageLabel' => false,
                        'nextPageLabel' => false,
                        'maxButtonCount' => 5,

                        'options' => [
                            'tag' => 'div',
                            'class' => 'pagination',
                            'id' => 'pager-container',
                        ],

                        'linkOptions' => ['class' => 'page-link'],
                        'disabledPageCssClass' => 'page-item disabled',
                        'activePageCssClass' => 'page-item active',
                    ],

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LaXiTy, 2019-03-25
@LaXiTy

It makes more sense to do this through DI , specifying the default parameters for this class in your config file.
For example, in your case it will be like this

// file config/main.php
[
    //...
    'components' => [//...
    ],
    'container'  => [
        'definitions' => [
            'yii\grid\GridView' => [
                'firstPageLabel' => false,
                'lastPageLabel'  => false,
                'prevPageLabel'  => false,
                'nextPageLabel'  => false,
                'maxButtonCount' => 5,

                'options' => [
                    'tag'   => 'div',
                    'class' => 'pagination',
                    'id'    => 'pager-container',
                ],

                'linkOptions'          => ['class' => 'page-link'],
                'disabledPageCssClass' => 'page-item disabled',
                'activePageCssClass'   => 'page-item active',
            ],
        ],
    ],
],

In this case, all new objects of the GridView class will come with the specified default settings.
Here about configuring and be sure to read about DI

D
Dmitry, 2019-03-21
@slo_nik

Good afternoon.
Try to create an array in params.php.
In gridview pass like this
'pager' => Yii::$app->params['array_settings']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question