Gridview sort


I’m following this tutorial .

Is there a way to sort the gridview by another attribute such as for example ‘city_population’ which is not a tour attribute?

To display it in gridview I use city.city_population but I’m unable to sort and search by that column.

Thank you very much

Have you modified your model properly?

Please post the relevant code parts if it’s still not working.

Thank you very much for your kind attention.

My real code is similar. A user have one or more lists of stickers of a collection. In the table user_lists there’s only album_id.

In the db table album there are album_id and album_name and publication_year.

So in the gridview where are displayed user’s lists I want to display album_name instead of album_id (and that’s ok) and publication_year as a new column.

In gridview


                'attribute' => 'album_id',

                'label' => Yii::t('app','Album Name'),

                'value' => 'album.album_name',




                'attribute' => 'album_id',

                'label' => Yii::t('app','Album Year'),

                'value' => 'album.publication_year',


But I don’t know how modify the SearchModel to have this field searchable and sortable.

Thank you

The necessary steps are explained in the link I posted, which part are you struggling with?

Thank you, Thank you, Thank you!

It works! :D