1

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

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%;')
),
4

1 回答 1

1

在模型类中:

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 以反映新的自定义字段。

于 2013-08-16T09:29:51.840 回答