php - Yii search CDbCriteria "$sort->attributes" is not sorting "<db column> as attempts" -


i need way sort grid clicking column header...

public function search() {     $criteria = new cdbcriteria;     $criteria->select = 'cac.id, cac.client_name, cac.phone, cd.code, t.outgoing_call_date, (select count(id) css_ataps_calls caller_id = cac.id , start_date = current_date) attempts; 

sorting section

$sort = new csort(); $sort->defaultorder = 'cac.id'; $sort->attributes = array('client_id', 'attempts'=>array('asc'=>'attempts', 'desc'=>'attempts desc')); 

sgridview code

array('name'=>'attempts',       'type'=>'raw',       'value'=>'$data->attempts',       'htmloptions'=>array('style'=>'width:15%;text-align:center;'),       'headerhtmloptions'=>array('style'=>'width:15%;') ), 

in model class:

public $attempts; 

and

$dataprovider=new cactivedataprovider('...', array(     'sort'=>$sort), )); 

and in view grid:

'columns'=>array(     ...,     array(         'name'=>'attempts',               'htmloptions'=>array('style'=>'width:15%;text-align:center;'),         'headerhtmloptions'=>array('style'=>'width:15%;')     ),  ) 

you may need update attributelabels in model reflect new custom field.


Comments