1

I need to show highest amount on the top in yii Cgridview.

I have two models: members and billing, member_id is foregion key in billing model. My Model Function:

   public function getImportantMembers(){       
    $criteria = new CDbCriteria;        
    $criteria->select ='t.*,b.billing_id,b.amount,b.billing_date,b.member_id,b.billing_status , sum(b.amount) AS totalamount';      
    $criteria->join = 'JOIN billing AS b ON b.member_id = t.id ';
    $criteria->addCondition("b.billing_date > DATE_SUB(NOW(),INTERVAL 2 MONTH)  AND b.billing_status='c' AND b.amount > 150 ");               
    $criteria->group  = 't.id';        
    $criteria->order = " totalamount DESC";                   

    return new CActiveDataProvider(get_class($this),array(
        'pagination'=>array(            
            'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),),          
            'criteria'=>$criteria,
    ));
}

but this function not showing correctly highest amount at the top or amount DESC How I can fix this?

4

1 回答 1

0

在您的模型中定义关系并在您的标准中使用它们。然后将 CSort 对象传递给 DataProvider,如下所示。您可以定义自定义排序参数,只要您在模型中定义它们即可。

return new CActiveDataProvider( 'Model', array(
    'criteria'=>$criteria,
    'sort'=>array(
        'attributes'=>array(
            ...........
            ...........

            '*',
        ),
    ),
));

有关详细信息,此链接将有所帮助。 http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

如果该链接不能帮助发布您的两个表的模型代码,我将尝试提供一些示例代码。

于 2013-09-30T11:38:03.913 回答