I’ve read all posts I can find on filtering and sorting CGridView and relational data. The problem I have is that I only seem to be able to do one or the other. Not both.
Sorting should be possible by defining an CSort object that can be used with the CActiveDataProvider. You should define something like this in the search() function of your model:
$criteria->with('kategori');
//.....criteria stuff goes here
$sort = new CSort;
$sort->defaultOrder = 'kategori.name ASC';
$sort->attributes = array(
'name'=>'kategori.name',
);
return new CActiveDataProvider('get_class($this)', array(
'criteria'=>$criteria,
'sort'=>$sort
));
EDIT:
I just saw that you do not use the search() function in your examples. Just add the CSort to whatever function you are using instead. Just make sure you are sending the CSort object and the dataprovider to CGridView