![](/img/trans.png)
[英]How to implement sorting on DATE/TIME column in CGridView by using CDbCriteria Yii
[英]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.