1
我有以下CGRID視圖如何做cgridview默認的排序在yii1
$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,
));
}
所以我基本上要在cgridview中值顯示id(主鍵)的降序。可能嗎?
我試圖像這樣沒有成功
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'id ASC',
),
' 'defaultOrder'=> 'ID DESC','? – Criesto
@Criesto不,它沒有工作。有什麼辦法可以在視圖文件中而不是在模型中執行此默認排序? – Bloodhound
您是否收到任何錯誤?在視圖中執行此操作並不是一個好主意,您應該遵循MVC結構,並且爲什麼在'gridview'小部件中有'[/ size]'? – Criesto