2011-10-03 122 views
2

我已經用yii Cgridview中的自定義字段創建,但如何使這個排序。自定義字段值來自模型中的函數。我想讓這個領域排序? 有人可以幫我嗎?CGridview自定義字段排序

+1

我們需要更多的信息 - 你定義自定義排序?你在使用什麼數據提供者? – ldg

回答

3

在你的模型,其中customField是您的字段的名稱的search功能:

// ...other criteria... 
$criteria->compare('customField',$this->customField); 

$sort = new CSort(); 
$sort->attributes = array(
    'customField'=>array(
     'asc'=>'customField ASC', 
     'desc'=>'customField DESC', 
    ), 
    '*', // this adds all of the other columns as sortable 
); 

return new CActiveDataProvider($this, array(
    'criteria'=>$criteria, 
    'sort'=>$sort, 
)); 

您可能還需要更新rulesattributeLabels在模型以反映新的自定義字段。

+0

您能描述模型中的** rules **和** attributeLabels **需要哪種更新來反映新的自定義字段。更多細節請 –