How To Sort A Complicated Column ('value'=>Array($This, 'myfunc')) In Yii Cgridview

my view:

 11     'columns'=>array(

  3             array('name'=>'count',

  2                 'headerHtmlOptions'=>array('width'=>'100px'),

  1                 'value'=>array($this, 'getCount'),

  0                 'header'=>'商家数量',                                                                                                                                               

  1                 'type'=>'raw',

  2                 'sortable'=>true,

  3             ),

my controller:

  0     public function getCount($data, $row, $c)                                                                                                                                       

  1     {

  2         return $this->actionSourceMoreIDARRAY[$data['id']];

  3     }

from the classBook I know that:

$sortable property —

Defaults to true. Note that if name is not set, or if name is not allowed by CSort, this property will be treated as false.

Of course , my column’s value is from a function …

anyone give me a solution? thanks a lot .

Hi phpgcs,

When working with CActiveDataProvider or CSqlDataProvider, the sorting is (and must be) executed on the SQL level. So if you are getting ‘count’ by a php function, you can not sort by it.

Ah, welcome to the forum, BTW. :)

thanks a million for your reply , you remind me to know more about the working principle of yii frame … thanks again. :rolleyes: