How to make CGridView header column titles clickable?

By default, columns in CGridView are clickable and enable the user to sort asc or desc. But when you add a custom column, or replace an FK id with its related data, the column title becomes unclickable. Is there a way to re-establish this click and sort behaviour?

Lots of posts here on this.

Basically you need to:

Alter your query to include the related data using ‘with’ and ‘together’=>true

Create a virtual attribute in your model for the related data item

Alter your Criteria to include an operator (compare, etc) for the virtual attribute

make virtual attribute safe on search

Please check this wiki: