GridView: sort relational data

Hey, it’s me again :D

I have gone so far, that my relationship problem is solved (see here). Now i managed to get the model relation searchable in my grid view. This video helped me with it.

But i can’t how to make my GridView header sortable? It still sorts after the category_id when I’m clicking on it. :huh:

Tried with this:


    $dataProvider->sort->attributes['category'] = [

      'asc' => ['categories.description' => SORT_ASC],

      'desc' => ['categories.description' => SORT_DESC],

    ];

Thanks’ for any tip :)

Hi!

Have you read this already?

http://www.yiiframework.com/wiki/621/filter-sort-by-calculated-related-fields-in-gridview-yii-2-0/

Was very useful for me.

If you have read this already:

More of your code would be needed to see what is going wrong.

(The SearchModel Class and the GridView Code)

Regards

I set default sort on model like this

$dataProvider = new ActiveDataProvider([

        'query' => $query,


        'sort'=> ['defaultOrder' => ['jam_estimasi'=>SORT_ASC]]


    ]);