Gridview Custom Column Loses Sort Link

Hello.

First of all, GREAT framework and thanks for all the work put in to it and all the advice given by those knowledgeable of Yii.

I am using the advanced template and created some paged using CRUD.

On the GridView created I started to experiment with it and change some column configurations.

I started with changing the column width and it worked but then I lost the column title.

So I added the value attribute and it reappeared but with no sort link.

How do I go about reaquiring the column title with it’s sort ability?




<?= GridView::widget([

	'dataProvider' => $dataProvider,

	'filterModel' => $searchModel,

	'columns' => [

		[

			'class' => 'yii\grid\SerialColumn',

			'headerOptions' => ['style' => 'width:40px']

		],

		'id',

		[

			'value' => 'longName',

			'header' => 'Long Name',

                        'headerOptions' => ['style' => 'width:200px']

		],

		'shortName',

		'website',

		'lastUpdate',

		// 'sortOrder',

		// 'insertDate',

		['class' => 'yii\grid\ActionColumn'],

	],

]); ?>



Thanks

Scotty

You must pass the attribute property for each column for it to be sortable.

Also header will overwrite the header column content, use label instead:




  [

                    'attribute' => 'longName',

                    'label' => 'Long Name',

                    'headerOptions' => ['style' => 'width:200px']

  ],



Btw: you may set labels in your ActiveRecord by defining it in the attributeLabels() method.

Dangit. I was so close.

I had the attribute in there like Kartik suggested (thanks) but my stupid header was overriding it as CeBe pointed out.

Time to go play with the attributeLables() now.

Again thanks.

Scotty

How to change the format class & properties attributes of entire the gridview ? I want to set my own styles