我有以下cgrid视图
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'complaint-job-grid',
'dataProvider'=>$model->search($complaint),
//~ 'filter'=>$model,
'columns'=>$columns,
'enableSorting'=>true,
));
我的型号代码是
public function search($complaint)
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('complaint_job','user');
$criteria->compare('complaint_job.job_desc',$this->job_search, true);
if($this->user_search)
$criteria->addSearchCondition('CONCAT(first_name," ",last_name)', $this->user_search);
$criteria->compare('complaint_id',$complaint);
$criteria->compare('id',$this->id);
$criteria->compare('job_id',$this->job_id);
$criteria->compare('local_description',$this->local_description,true);
$criteria->compare('employee_id',$this->employee_id);
$criteria->order = 't.id ASC';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
所以我基本上想要的是以id(主键)的降序显示cgridview中的值。有可能吗?
我试着这样做没有成功
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'id ASC',
),
答案 0 :(得分:0)
你正在CDbCriteria中进行排序; 这就是为什么在使用CActiveDataProvider的CGridView中排序不起作用的原因。 从您的模型中删除:
$criteria->order = 't.id ASC';
并添加到CActiveDataProvider
'defaultOrder'=>'t.id ASC',