cgridview and sorting problem

Hello

In model:




public function search()

{

	$criteria=new CDbCriteria;

        $criteria->select ='t.*,

        TIMESTAMPDIFF(MINUTE , now() , (t.startdate + interval t.days day)) as timetoend';



in view:




<?php


    $dataProvider=$model->search();

    $dataProvider->sort->attributes=array(

        'timetoend',

    );


   $this->widget('application.components.GridView', array(



now i cant sort by time toend becaouse it sorting by t.timetoend




SQL: SELECT t.*, TIMESTAMPDIFF(MINUTE , now() , (t.startdate + interval t.days day)) as timetoend FROM `User` `t` ORDER BY `t`.`timetoend` LIMIT 20



i need a method to tell model to use or not to use prefix in sorting condition.

You can also use another array to define a sort attribute. Then you can specify the SQL condition for each direction. The columns will not be prefixed in this condition:


'attributes'=>array(

  'timetoend'=>array(

      'asc'=>'timetoend',

      'desc'=>'timetoend desc',

  ),

Look here for even more details: http://www.yiiframework.com/doc/api/CSort#attributes-detail