本文介绍了Yii CGrid分页和CArrayDataProvider排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模型中构建了一个自定义函数并返回原始数据:

I built a custom function in my model and return the raw data:

function(){
...
$connection=Yii::app()->db;
$command=$connection->createCommand($sql);
$rows=$command->queryAll();
return $rows;
}

$ campModel = $ model->函数.

$campModel = $model->function..

然后我在CArrayDataProvider中使用这些行:

I then use those rows in CArrayDataProvider:

$dataProvider=new CArrayDataProvider($campModel);

最后,我尝试使用CGrid进行查看:

Finally i'm trying to view using CGrid:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'bo-campaigns-grid',
'dataProvider'=>$campModel,...

我猜想这与CGrid分页的方式有关...但是我迷路了感谢您的帮助:)

I'm guessing this has to do with the way CGrid is paging...but i'm lostThanks for the help :)

推荐答案

创建一个新的CSort和CPagination对象,并将它们分配给您的数据提供者,因为CArrayDataProvider没有定义它们.这是CSort创建的示例:

Create a new CSort and CPagination objects and assign them to your dataprovider, because CArrayDataProvider doesn't have them defined. Here is an example of CSort creation:

$dataProvider=new CArrayDataProvider($campModel);
$sort = new CSort();
$sort->attributes = array(
            'fecha'=>array(
                'asc'=>'dateA DESC',
                'desc'=>'dateA ASC',
            ),
);
$sort->route = 'myController/myMethod';
$dataProvider->sort = $sort;
$dataProvider->sort->defaultOrder='dateA DESC';

这篇关于Yii CGrid分页和CArrayDataProvider排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 10:11