Yii2: Sorting not working on some options of GridView

Created on 2 Feb 2014  路  9Comments  路  Source: yiisoft/yii2

Sorting Works in 1st case and not in 2nd case.

'columns'=>['name'],
'columns'=>[
            'label' => 'name',
            'header' => 'Event Name',
            'value' => function($model) {
                 return $model['name'];
            }
],

Most helpful comment

use label.

All 9 comments

you have incorrect column setup. please refer to official documentation for this case.

I have searched everything, but cannot find.

There must be attribute for sorting

'columns'=>[
'attribute' => 'name',
...
],

Yep, if no attribute is specified you can not sort.

Want to change Header, but when I add 'header', then Sort does not work.

[
                        'attribute' => 'name',
                        'header' => 'Event Name',
],

use label.

@Ragazzo Why does 'header' affects sorting and 'label' does not?

because header will overwrite the full header cell content, while label defines that label that is used for the colum, i.e. to fill the header or to generate the link dependent on what is needed.

@cebe Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sapsxxxil picture sapsxxxil  路  50Comments

AstRonin picture AstRonin  路  49Comments

alexraputa picture alexraputa  路  53Comments

schmunk42 picture schmunk42  路  47Comments

samdark picture samdark  路  52Comments