A
A
Artyom2015-05-05 13:56:53
Yii
Artyom, 2015-05-05 13:56:53

How to disable counter and contentOptions in gridview in yii2?

How can I disable the counter in Yii2? The column name is # and there the numbers go in order.
And why with this code


'columns' => [
[
'class' => 'yii\grid\SerialColumn',
'contentOptions' => function ($model, $key, $index, $column) {
return ['class' => 'myclass' ];
},
],

Only once to the first cell adds. How to add to all? How many fields so many times to ask? It's stupid.
And how to add a class to th? Well, what's in the title. Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2015-05-05
@DeOne

The counter is a SerialColumn, everything is written correctly.
The class for the header can be set via www.yiiframework.com/doc-2.0/yii-grid-column.html#...

GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                        'class' => 'yii\grid\SerialColumn',  // <- колонка со счетчиком
                        'headerOptions' => ['class' => 'some-class'] // кастомный класс для заголовка
            ],
            'id',
            'text:raw',
            'created',
            'updated',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question