Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Cgridview -> Sort By Virtual Attribute

$
0
0
Well, this is my "Users" model:

public $fullname;

{other code here - not really important for this problem}

public function search()
{

         $sort = new CSort();
         $sort->attributes = array('*', 'CONCAT(surname, ", ", forename) AS fullname');
         $sort->defaultOrder = array('fullname' => CSort::SORT_ASC);

$criteria=new CDbCriteria;
         $criteria->select = array('*', 'CONCAT(surname, ", ", forename) AS fullname');
         $criteria->compare('id', $this->id);
$criteria->compare('login', $this->login, true);
         $criteria->compare('surname', $this->surname, true);
         $criteria->compare('forename', $this->forename, true);
         $criteria->compare('email', $this->email);
$criteria->compare('CONCAT(surname, ", ", forename)', $this->fullname, true);
$criteria->compare('company_id', $this->company_id);
$criteria->compare('grupa', $this->grupa);
$criteria->compare('active', $this->active);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
    'pagination'=>array('pageSize'=>10),
    'sort' => $sort,
));
}


The CGridView widget generated with such a data provider works fine but for whatever reason "Fullname" column is not sortable. Can anybody here give me a clue why this problem occures???

Thanks ahead!

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>