繁体   English   中英

Yii搜索CDbCriteria“ $ sort-&gt; attributes”未排序“ <db column> 作为尝试”

[英]Yii search CDbCriteria “$sort->attributes” is not sorting “<db column> as attempts”

我需要一种通过单击列标题来对网格进行排序的方法...

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

分拣科

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

SGridView代码

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

在模型课中:

public $attempts;

$dataProvider=new CActiveDataProvider('...', array(
    'sort'=>$sort),
));

并在视图网格中:

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

您可能还需要更新模型中的attributeLabels以反映新的自定义字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM