012
(Zerododici)
October 5, 2016, 7:23am
1
Hi,
I’m following this tutorial http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/ .
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
patrickm
(Yiiframework)
October 5, 2016, 7:46am
2
Have you modified your model properly?
http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#working-with-model-relations
Please post the relevant code parts if it’s still not working.
012
(Zerododici)
October 5, 2016, 8:07am
3
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
patrickm
(Yiiframework)
October 5, 2016, 8:44am
4
The necessary steps are explained in the link I posted, which part are you struggling with?
012
(Zerododici)
October 5, 2016, 10:19am
5
Thank you, Thank you, Thank you!
It works!